...

View Full Version : help with onClick and onMousedown



kiransarv
11-16-2008, 08:32 AM
Hi all,

My browser is firefox.

I have the piece of code

<html>
<head>
<script type="text/Javascript">

function load(url,event)
{
location.href=url;
}

</script>
</head>
<body>
<a href="http://www.yahoo.com" onClick="load('http://www.google.com'); return false;">Yahoo</a>
</body>
</html>

The code works fine when i press left button. But it will not redirect me to google when i press both middle and right(open link in new tab).

Then i tried this.

<html>
<head>
<script type="text/Javascript">

function load(url,event)
{
var button = event.which;
//document.write(button);

if(button==1)
{
window.location = url;
}

if(button==2)
{
window.open(url);
}

}

</script>
</head>
<body>
<a href="http://www.yahoo.com" onMouseDown="load('http://www.google.com',event); return false;">Yahoo</a>

</body>
</html>

It is displaying button values but unable to redirect. So How can i redirect to google when i click yahoo link in all the three cases.

regards
kiran

mjlorbet
11-16-2008, 08:51 AM
use document.location instead of window.location or location.href

document.location.href is a good way to retrieve the location of the document you're looking at but document.location is the way to assign



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum