I need to simulate a click on an href anchor

I have the following anchor tag that I need to simulate clicking on it on the page onload event.

Basically I need that href tag to be "executed"

[code]
<a id="ooyalaPlayer_1w0o4_fux6xvhi" title="MyGizmo :: Presents..." rel="rokbox[720 404]" href="http://vmysite.com/9xbjlqOsoApB&autoplay=1/ooyalaPlayer_1w0o>Click me to watch video</a>
[/code]
<a id="ooyalaPlayer_1w0o4_fux6xvhi" title="MyGizmo :: Presents..." rel="rokbox[720 404]" href="http://vmysite.com/9xbjlqOsoApB&autoplay=1/ooyalaPlayer_1w0o>Click me to watch video</a>

Open in new window

JossifAsked:
Who is Participating?
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
Yes it is


<script>
// allow firefox to handle a click - code possibly by Jason Karl Davis
if(typeof HTMLElement!='undefined'&&!HTMLElement.prototype.click)
HTMLElement.prototype.click=function(){
var evt = this.ownerDocument.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
this.dispatchEvent(evt);
}
</script>
 
 
document.getElementById('ooyalaPlayer_1w0o4_fux6xvhi').click();

Open in new window

0
 
lyhanCommented:
you can set windows.location.href = any given anchor in the onload function,



windows.location.href = "http://vmysite.com/9xbjlqOsoApB&autoplay=1/ooyalaPlayer_1w0o"

<script language="javascript" type="text/javascript">
 
 
 
windows.location.href ="http://vmysite.com/9xbjlqOsoApB&autoplay=1/ooyalaPlayer_1w0o";
 
 
</script>

Open in new window

0
 
JossifAuthor Commented:
But that will reload the page with that URL... And as you see, the href call a function via a rel so this will not work, would it?

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
lyhanCommented:
I see, please try

document.getElementById('ooyalaPlayer_1w0o4_fux6xvhi').click();

ooyalaPlayer_1w0o4_fux6xvhi is the id by the way
0
 
JossifAuthor Commented:
Nope.... It throws an error:

document.getElementById("ooyalaPlayer_1w0o4_fux6xvh").click is not a function

I think that the click event is just for buttons and not for anchors
0
 
JossifAuthor Commented:
I meant:


document.getElementById("ooyalaPlayer_1w0o4_fux6xvhi").click is not a function
0
 
JossifAuthor Commented:
Basically the rel in that href is calling mootools and I think that's the problem.

0
 
lyhanCommented:
in your code snippet, it's malformed

<a id="ooyalaPlayer_1w0o4_fux6xvhi" title="MyGizmo :: Presents..." rel="rokbox[720 404]" href="http://vmysite.com/9xbjlqOsoApB&autoplay=1/ooyalaPlayer_1w0o<B>"</B>>Click me to watch video</a>

href="..."
0
 
lyhanCommented:
it's very possible. It's not easy to find a way to simulate user clicks across different browsers
0
 
JossifAuthor Commented:
@mplungjan: I am testing your solution later today. If it works, 500 points for you!

Will this work in MSIE 7, FF and Safarr?
0
 
Michel PlungjanIT ExpertCommented:
The code I gave is for FF, MSIE and Safari should work with the click anyway.
0
 
JossifAuthor Commented:
500 points for you, mplugian!
0
All Courses

From novice to tech pro — start learning today.