Solved

have an onload which simulates the click of an a href

Posted on 2006-06-09
4
695 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

728 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