Hi guys. I have a quick question. What's the code for having a link with the id "autoid" clicked when the body of my html code loads? Thanks, Alex
Basically, I have link on my page. I want to use the click function of JavaScript to automatically click it when the page loads. The id of the link is 'autoid'.
You can use this <html> <head> <script> window.onload = function(){ document.getElementById("autoid").click(); } </script> </head> <body> <a href="http://rubensargsyan.com" id="autoid">Ruben Sargsyan's personal website</a> </body> </html> Code (markup): but it doesn't work on firefox. Or you can use this: <html> <head> <script> window.onload = function(){ location.href = document.getElementById("autoid"); } </script> </head> <body> <a href="http://rubensargsyan.com" id="autoid">Ruben Sargsyan's personal website</a> </body> </html> Code (markup):
this javascript code is very good. but how can i set a timer. i mean when site is loading, where i have place that code, the code is clicking on the link button. that is some bit bad. i want that the code clicking to the button link after 5 seconds when site is complete loading. any ideas???
window.setTimeout('clickit()',5000); function clickit(){ location.href = document.getElementById("autoid"); } HTML: This should work
Hi, I agree with above codding solution. But in place of timer. U can use window.onload=functionName; it is too better than javascript timer function. Vishal
Hello i found a website for this http://www.oklearncode.com/get-onload-click-link-automatically-script/