Synthetic click on link doesn't follow link

P

Peter Michaux

Hi,

Below is an example of a synthetic click in Firefox. The browser does
not follow the link. Is that the just the way synthetic clicks work of
am I doing something wrong? I know the synthetic click occurs because
if I add an onclick attribute to the link the handler runs. Any ideas?

Thanks,
Peter

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>

<title>synthetic click</title>

<script type="text/javascript">

window.onload = function() {
var el = document.getElementById('myLink');

var e = document.createEvent("MouseEvents");

e.initMouseEvent('click', // event type
true, // can bubble
true, // cancelable
window, // abstract view
0, // detail
0, // screenX
0, // screenY
0, // clientX
0, // clientY
false, // ctrl key
false, // alt key
false, // shift key
false, // meta key
0, // button
null); // related target

el.dispatchEvent(e);

}

</script>

</head>
<body>

<p><a id="myLink" href="http://www.yahoo.com">myLink</a></p>

</body>
</html>
 
P

Peter Michaux

Hi,

Below is an example of a synthetic click in Firefox. The browser does
not follow the link. Is that the just the way synthetic clicks work of
am I doing something wrong? I know the synthetic click occurs because
if I add an onclick attribute to the link the handler runs. Any ideas?


After some more research I discovered that this is a known problem.
The solution is just to manually set the location.href property.

Thanks for reading.

Peter
 
L

-Lost

Peter said:
After some more research I discovered that this is a known problem.
The solution is just to manually set the location.href property.

Can you provide the location of this solution?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top