[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

I need to simulate a click on an href anchor

Posted on 2009-05-19
12
Medium Priority
?
1,276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 

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
 
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 2000 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

Cyber Threats to Small Businesses (Part 2)

The evolving cybersecurity landscape presents SMBs with a host of new threats to their clients, their data, and their bottom line. In part 2 of this blog series, learn three quick processes Webroot’s CISO, Gary Hayslip, recommends to help small businesses beat modern threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

656 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