Solved

I need to simulate a click on an href anchor

Posted on 2009-05-19
12
1,264 Views
Last Modified: 2013-12-06
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

0
Comment
Question by:Jossif
  • 6
  • 4
  • 2
12 Comments
 
LVL 2

Expert Comment

by:lyhan
ID: 24427816
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
 

Author Comment

by:Jossif
ID: 24427844
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
 
LVL 2

Expert Comment

by:lyhan
ID: 24427864
I see, please try

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

ooyalaPlayer_1w0o4_fux6xvhi is the id by the way
0
 

Author Comment

by:Jossif
ID: 24427922
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
 

Author Comment

by:Jossif
ID: 24427931
I meant:


document.getElementById("ooyalaPlayer_1w0o4_fux6xvhi").click is not a function
0
 

Author Comment

by:Jossif
ID: 24427971
Basically the rel in that href is calling mootools and I think that's the problem.

0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 2

Expert Comment

by:lyhan
ID: 24428006
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
 
LVL 2

Expert Comment

by:lyhan
ID: 24428020
it's very possible. It's not easy to find a way to simulate user clicks across different browsers
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 24429019
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
 

Author Comment

by:Jossif
ID: 24433593
@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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24433806
The code I gave is for FF, MSIE and Safari should work with the click anyway.
0
 

Author Comment

by:Jossif
ID: 24434127
500 points for you, mplugian!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Ransomware continues to be a growing problem for both personal and business users alike and Antivirus companies are still struggling to find a reliable way to protect you from this dangerous threat.
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now