-2

Here is the html of anchor tag:

<a href="javascript:void(0)" id="myid">JavaScript Link Code</a>

And this is the Javascript function's statement (not Javascript link code) which I am using

simulate(document.getElementById("myid"), "click");

Please help me. I want to auto click 'Javascript Link Code' between <a> </a> when page loads.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

0

If you want to call a function on load, there is a simple way.

window.onload = function() {
  someCode();  // call here whatever JavaScript Code you want on load
};

Why try to 'simulate' a click only to call its function?

You can get and execute the code like this

var code = document.getElementById('myid').textContent;
eval(code);

But it's not wise to execute code like this.

AntouanK
  • 4,880
  • 1
  • 21
  • 26