Stuck in onclick property
|
|
I want to simulate the click on an Anchor tag. I retrieve the DOM element and can read the contents of the onclick property (it's something like "(new Image()).src = '/ajax/sdfafaf'; return"), but I haven't found the way to execute it. |
|
|
I've not tried it, but wouldn't something like the following work... newScript = document.createElement("script");
newScript.type = "application/x-javascript";
newScript.innerHTML = "(new Image()).src = '/ajax/sdfafaf'; return)";
document.getElementsByTagName("head")[0].appendChild(newScript)
|
|
|
It's easier to create a fake event:
var myNode = document.getElementById("mynodeid");
var clickEvt = document.createEvent("MouseEvent");
clickEvt.initEvent("click", true, true);
myNode.dispatchEvent(clickEvt);
|
|
|
Thanks Mindeye! It worked. Actually it was the mousedown event that triggered the action. |
