PDA

View Full Version : auto click using .click()



ajmalhuuss
05-28-2010, 12:16 AM
Hey guys just need a little help.

I need to create a little script that clicks a link automatically and opens it up in a new page.

So far I have this:



<head>
<script>
function autoClick(){
document.getElementById('linkToClick').click();
}
</head>
<body onload="setTimeout('autoClick();',3000);">
<a id="linkToClick" href="http://www.google.com" target="_blank">GOOGLE</a>
</body>
It works but the problem is that IE popup blocker keeps blocking the new window.

Is there a way to do the same thing with javascript without it having blocked by IE popup blocker?
[/CODE]

vwphillips
05-28-2010, 09:23 AM
guess you are aware that .click() is IE only

there will be a warning if you are testing locally but it should be OK(IE only) online.

jscheuer1
05-28-2010, 04:01 PM
Well, you will need to close the script tag:


<head>
<script>
function autoClick(){
document.getElementById('linkToClick').click();
}
</script>
</head>
<body onload="setTimeout('autoClick();',3000);">
<a id="linkToClick" href="http://www.google.com" target="_blank">GOOGLE</a>
</body>

And it is IE only. Even in IE, if the pop up blocking settings are high enough, the blocker will still block it. Like, if clicking on the link is blocked (highest setting - block all pop ups), then the script won't work either.


You really shouldn't be popping things up in a window though, there are almost always better, though often more complicated ways to accomplish whatever you are trying to do, ways that will work cross browser and not be subject to pop up blocking.