tags:

views:

322

answers:

2

Hai i want to generated an automated click event. I am working in php server, i Know Javascript. Below is my Code

<script language="javascript">

function autoClick() {
var elm=document.getElementById('thisLink');
    elm.click();
     document.getElementById('thisLink').click();
    }

</script>
</head>

i put this on inside the body tag :

onload="setTimeout('autoClick();',3000);"

and inside the a tag :

href="./apage.php" id="thisLink" name="thisLink" target="newWindow"

But it doesn't work in MOzilla Is any solution , 0r any other solution ???

Thanks in advance

A: 

You could try JQuery's trigger function.

$('#thisLink').trigger('click');

This should possibly work although I haven't tested it.

JQuery: http://jquery.com

doc: http://docs.jquery.com/Events/trigger#eventdata

andho
Did the OP ask for a jquery solution? No? Then you need to provide *both*.
annakata
ok that's understandable but what does OP stand for?
andho
@andho OP stands for »original poster«
knittl
+1  A: 

Element.click works only on input elements on Mozilla. Try something like

function autoClick() {
  var elm=document.getElementById('thisLink');
  document.location.href = elm.href;
}

instead, or if you prefer opening the link into a new window,

function autoClick() {
  var elm=document.getElementById('thisLink');
  window.open(elm.href, 'autoclickwindow');
}
kkyy
But this wouldn't open the window in a new tab.
andho