I am having trouble with the showHide function. I have one page (Pg1) that contains several divs which all showHide just perfectly. However, when I call the showHide function from one of the other pages (Pg2, Pg3, etc) using href, (Pg1) loads and the correct div requested shows, but the page loads in the browser with the content of that div at the top. I need this function to work so that the entire page is in view, but the text in the div requested simply shows in the appropriate cell on that page. I know most people are loving the jump features, but i don't want my page to jump, I need it to remain fully in view weather using the showHide function from within the same page, or calling it from an external link. Can anyone help? I've included code below for both working (within page) and malfunctioning (when calling from an externalpage)
Thanks in advance
malfunctioning (when calling from an externalpage)
Code:
<script type="text/javascript">
function Show(What, CheckURL)
{
var a, i;
if (CheckURL) {
i = document.URL.indexOf("#");
if(i != -1) {
Show(document.URL.substring(i+1,document.URL.length));
return;
}
}
if (!document.getElementsByTagName)
return;
a = document.body.getElementsByTagName("div");
if (a.length == 0)
return;
if (typeof a[0].style != 'object')
return;
if (typeof a[0].style.display == 'undefined')
return;
for (i = 0; i < a.length; i++) {
if (a[i].className != "section")
continue;
if (a[i].id != What)
a[i].style.display = "none";
else
a[i].style.display = "block";
}
return true;
}
</script>
Then within the body:
Code:
<a href="javascript:parent.location.replace('javaswitch.html?showHide=#dd')";>
I've also tried
<a href="javaswitch.html"; onClick="Show('#dd')">
which also works, but has the same malfunction.
working (within page) showHide
Code:
<script type="text/javascript">
function Show(What, CheckURL)
{
var a, i;
if (CheckURL) {
i = document.URL.indexOf("#");
if(i != -1) {
Show(document.URL.substring(i+1,document.URL.length));
return;
}
}
if (!document.getElementsByTagName)
return;
a = document.body.getElementsByTagName("div");
if (a.length == 0)
return;
if (typeof a[0].style != 'object')
return;
if (typeof a[0].style.display == 'undefined')
return;
for (i = 0; i < a.length; i++) {
if (a[i].className != "section")
continue;
if (a[i].id != What)
a[i].style.display = "none";
else
a[i].style.display = "block";
}
return true;
}
</script>
Then within the body:
Code:
<a href="javascript:showHide('#da')"; class="ms_leftnav" onClick="Show('da');">da title</a>
I don't really understand why the code within the page is working and the code linking externally is not - any help is appreciated.