Firefox 5 .click is recognized but .click() not works and page frezees
Note : I don't to use "window.location.href" for IE. So that's why I am using .click(). It was working perfectly until FF5 was released.
Please help/guide.
Regards, Nitin
Modified
All Replies (8)
JavaScript is not supposed to be able to click a link in Firefox. I don't know why your code worked before.
You can "synthesize" a click on a link using a different slug of JavaScript. Here's an example:
var synth = document.createEvent("MouseEvents"); synth.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); document.getElementById('redirect_link').dispatchEvent(synth);
If that doesn't help, can you describe your application in more detail?
Hi jscher2000,
Appreciate your response. Let me elaborate a little bit more.
You are right that in FF you cannot click a link via javascript.
So what I did that I used to check if "if ((theLink) && (theLink.click))" exists and if not then use the "window.location.href = "http://www.google.com";". That's how it used to work in FF. If I used to run in IE then the "if" condition passes and the code .click() executes
However when I upgraded to FF5 then a strange thing happened. The code "if ((theLink) && (theLink.click))" used to pass (before that in all Ff version it never used to) and the code used to go inside the if condition which actually fires the .click() . However that doesn't work.
Why does FF5 behaves like this? why does it even pass the "if" condition when it cannot execute the .click(). Strangely there is no JS error in the console.
Thanks, nitin
Hmmm, I can't explain it. Maybe it's an HTML5 thing? Does it work differently if you disable the HTML5 parser (not that most users will do that, but just for testing)?
Please save any unfinished work first.
(1) In a new tab, type or paste about:config in the address bar and press Enter. Click the button promising to be careful.
(2) In the filter box, type or paste html5 and pause while the list is filtered
(3) Double-click html5.parser.enable to toggle it to false (it should turn bold).
Then return to the problem page and try the script again. Does that make any difference?
also the reason i am using .click() in IE because "window.location.href" does not pass REFERER in IE and there are some third party links that needs the same. FF passes the stored REFERER with "window.location.href"
Hi jscher2000,
No the html5 thing didn't worked
Thanks, Nitin
I don't even know how to go about starting to research this, other than to check for new complaints on bugzilla.mozilla.org.
Besides creating a mouse event, one other thought on a workaround would be to have your script insert a form with the action set to the intended destination and method=GET, then use the submit() method on the form.
Hi jscher2000,
You are right. One of our arch did suggested it. Its a great idea. So if I go with this approach will it also send the required REFERER for those third party sites?
Thanks, nitin
I think it will. You can monitor the headers that are sent if you have a tool such as Microsoft's Fiddler proxy.