PDA

View Full Version : Universal anchor script help



bigalo
08-15-2009, 03:48 PM
Hey guys,

In a previous post, while trying to get help, I was able to figure out a solution to using js to force a specific anchor call to jump after the page completely loads. The reason I am doing this is because the page I am linking to with anchors takes a long time to load and a standard browser anchor link sometimes does not work 100%. With that said, I would now like to make the script I wrote universal to get ANY anchor param in the url and jump to that spot on the page. Right now it's coded to just look for "#anchor". I want to re-code it so it will look for "#" + "anyAnchorName".


Page A:


<a href="pageB.html#anchor">Click</a>


Page B:


<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()">

Thanks in advance!