/    Sign up×
Community /Pin to ProfileBookmark

Jump to anchor tag onload

Hello all,

I needs some help. I currently have a script to jump to an anchor tag when the page loads:

[CODE]
<script type=”text/javascript”>

function goToAnchor() {
location.href = “myPage.html#myAnchor”;
}

</script>
[/CODE]

Now, I would like to take it a step further and would like to link from page A to page B that usually takes a while to load and once the page loads, run a script to jump to the specified anchor tag on the page after everything has loaded. I know I have to add some parameters at the end of the url link on page A, but that’s where I get stuck.

Can anyone please help?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Aug 10.2009 — And why aren't you simply using&lt;a href="pageb.html#whatever"&gt;Link&lt;/a&gt;And on pageb.html&lt;anything id="whatever"&gt;
Copy linkTweet thisAlerts:
@bigaloauthorAug 10.2009 — That method tries to go to the anchor tag prior to everything on the page loading. Once everthing on the page is finished loading, it jumps away from that anchor location. In essence, it jumps to the anchor too soon.
Copy linkTweet thisAlerts:
@bigaloauthorAug 12.2009 — Thanks for your help! but I think I came up with a solution. Here it is:


Page A:
[CODE]
<a href="pageB.html#anchor">Click</a>
[/CODE]




Page B:
[CODE]
<script type="text/javascript">
function load() {
var urllocation = location.href;
if(urllocation.indexOf("#anchor") > -1){
window.location.hash="anchor";
} else {
return false;
}
}
</script>


<body onload="load()">
[/CODE]
×

Success!

Help @bigalo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...