Solved

have an onload which simulates the click of an a href

Posted on 2006-06-09
4
681 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
  • 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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…
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…

759 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

19 Experts available now in Live!

Get 1:1 Help Now