• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 709
  • Last Modified:

have an onload which simulates the click of an a href

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
blue-genie
Asked:
blue-genie
  • 2
1 Solution
 
ZvonkoSystems architectCommented:
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
 
shaggy_the_sheepCommented:
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
 
blue-genieAuthor Commented:
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
 
shaggy_the_sheepCommented:
Great, glad i could help

Richard
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now