Forum Moderators: open

Message Too Old, No Replies

mouse clicks

         

kiransarv

2:30 pm on Oct 27, 2008 (gmt 0)

10+ Year Member



My java script code is:

-------------------
<html>
<body>
<head>
<script type="text/Javascript">
function load(url)
{
//var code = event.which;
//document.write(code);
document.open(url);
location.href = url;
}
</script>
</head>
<a href="http://www.google.com" onMouseDown="load('http://www.yahoo.com');">Google</a>
</body>
</html>
--------------------------------

When ever i do a mouse click (left,Right,Middle) it is redirecting to yahoo on same page. How can i track mouse events? Do they differ from browser to browser? And also when i press back button on the browser it is displaying a blank page instead of the html page. i have to press back button of the browser twice. How can i solve these problems? plzz help me in this...

regards
kiran

astupidname

1:18 am on Oct 28, 2008 (gmt 0)

10+ Year Member



And also when i press back button on the browser it is displaying a blank page instead of the html page. i have to press back button of the browser twice.

document.open(url);

Right there is the culprit, you are telling it to open a blank document. The document.open() function is used to open a blank page which will be written to with document.write() or document.writeIn() if those are used in the script. document.open is not for opening a url. So what is happening is it opens a blank document and then the url in the location.href= statement, in that order.

When ever i do a mouse click (left,Right,Middle)

onMouseDown="load('http://www.yahoo.com');">

Right there is the culprit here, you are using onmousedown, which means any button on the mouse. Should be onclick instead. Also, once this code is corrected you will need to return false in the onclick or else the links default action will occur. That means that the url in the href= will be opened.
While I do not condone what you are doing here, as a link should not be mislabled like this, and also it is quite pointless to open the url with the script when you can just do it with the links href=, maybe you are just doing it to learn. So here is how it will work:
<html>
<head>
<script type="text/Javascript">
function load(url)
{
location.href = url;
}
</script>
</head>
<body>
<a href="http://www.google.com" onclick="load('http://www.yahoo.com'); return false;">Google</a>
</body>
</html>