Welcome to WebmasterWorld Guest from 100.26.182.28

Forum Moderators: open

Message Too Old, No Replies

Onclick event not working in Firefox

Same code works in IE and Opera

     
8:11 am on May 13, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Jan 4, 2006
posts:307
votes: 0


<a href="download/filename.exe" onclick="trackit()"><img src="download/filename.jpg"></a>

<script language="javascript">
function trackit()
{
window.open("download/download.htm", "windowname", "settings");

return false;
}
</script>

This code is working fine in IE and Opera i.e. a new window opens (download/download.htm) by clicking on the image link but in Firefox the onclick event does not get triggered and the normal href get executed.

Any workarounds?

Milan

6:53 pm on May 13, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 26, 2004
posts:1497
votes: 0


Try changing the onclick to:

onclick="trackit(); return false;"

If the tracking still doesn't work then we'll need to see the contents of that function.

3:05 am on May 14, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Jan 4, 2006
posts:307
votes: 0


onclick="trackit(); return false;"

Did not worked. It still triggeres the href link and onclick gets bypassed. Moreover i have already added "return false;" in the function itself so it should be sufficient for it (my guess).

As i have already posted the actual code, the only thing trackit() function does is opening a new page of "download/download.htm" with window.open.

Milan

11:23 am on May 20, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 30, 2003
posts:3719
votes: 0


I just tried your code in Firefox and it worked fine.

You can also try:


<a href="#" onclick="trackit('download/download.htm')"><img src="download/filename.jpg"></a>
<script language="javascript">
function trackit(url)
{
var url;
window.open(url, "windowname", "settings");
return false;
}
</script>

dc

5:22 pm on May 20, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Jan 4, 2006
posts:307
votes: 0


dreamcatcher, thanks for the workaround. According to your code i found that onclick event was not passing any handler to the trackit() function and that is the reason why it was not working as it should be.

Finally i merged your code with mine as i had to put that onclick event on 50+ link tags and all is working fine in IE, FF and OP.

<a href="download/filename.exe" onclick="trackit(this)"><img src="download/filename.jpg"></a>
<script language="javascript">
function trackit(filename)
{
window.open(filename, "windowname", "settings");
}
</script>

Thanks again.

Milan

8:42 am on May 21, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 30, 2003
posts:3719
votes: 0


Glad you got it sorted Milan.

dc

3:39 pm on May 21, 2006 (gmt 0)

New User

10+ Year Member

joined:Nov 29, 2003
posts:2
votes: 0


...,"settings");

?

7:20 pm on May 21, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Jan 4, 2006
posts:307
votes: 0


...,"settings");

"resizable=0,toolbar=0,directories=0,status=0,location=no,scrollbars=no,width=1,height=1,top=200,left=100"

Milan

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members