?
Solved

have an onload which simulates the click of an a href

Posted on 2006-06-09
4
Medium Priority
?
700 Views
Last Modified: 2008-02-01
i have an ahref which has some java/javascript code that executes a search function, what i want to do is when that page loads call that method as well, i don't want to replicate that method, i want to simulate the link being clicked, can this be done and how do i go about doing it?

ta.
blu
0
Comment
Question by:blue-genie
[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
  • 2
4 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 16868766
In the body tag put this:
<body onLoad="theLink.click()">


...and immediately after the link put this script statement:
<script>theLink=document.links[document.links.length-1];</script>

0
 
LVL 5

Accepted Solution

by:
shaggy_the_sheep earned 2000 total points
ID: 16868774
Hi

Yes it can be done, well in IE anyway! I'll keep trying with the FF mehtod but here's a quicky that should do what you want.

Give the link that you want to be 'clicked' an id such as id="myLink".

Now put the body onload event to this onload="document.getElementById('myLink').click()"

That works for me in IE, no luck yet in FF. Do your needs require cross-browser compatability?

Richard
0
 
LVL 39

Author Comment

by:blue-genie
ID: 16868891
Thanks Richard, U Rock!!!!
Works a charm, we're not too concerned about cross -browser stuff for now, just need it to work in IE/
blu.
0
 
LVL 5

Expert Comment

by:shaggy_the_sheep
ID: 16868895
Great, glad i could help

Richard
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

764 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