Solved

I need to simulate a click on an href anchor

Posted on 2009-05-19
12
1,267 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Ransomware 9 82
How do I get rid of mic.com pop ups on my MAC? 9 1,076
Wallpaper not updating when file is swapped out 6 52
Renaming multiple file extensions using Powershell 4 37
PREFACE The purpose of this guide is to explain what the SEPC Status Utility is and how it works. I have written the utility using AutoIt and have included the source code for your review. You are welcome to modify the code to your liking, but I wi…
I recently had to create a utility which aim is to update McAfee's Virusscan and that had to be launched from a command line. I thought I’d share my experience with you. Why is it useful to be able to update an Antivirus from the command line?…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

911 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

21 Experts available now in Live!

Get 1:1 Help Now