Solved

have an onload which simulates the click of an a href

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

810 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