/    Sign up×
Community /Pin to ProfileBookmark

How Can I Call A Function from Another (self) Window?

Here’s the scenario:

I have 3 pages. The first page (index) contains links in the nav bar that call a showHide function to display the corresponding divs associated. (div a, div b, div c, etc)

The second and third pages (pages 2 & 3) load in the same window (self) when the corresponding navigation link is clicked. These pages contain all of the same nav bar links as the index page.

My question is:
How can I create the nav bar links on pages 2 & 3 so that when clicked they will open the index.html page in the same window (_self) and also load the correct div according to the corresponding nav bar link clicked.

I have the showHide function working properly with all of the divs within the “index.html” page.

I also have the nav bar links on pages 2 & 3 so that they can either link to “index.html” and load properly or link to “index.html” and load the proper div as requested, but the page doesn’t load properly.

The problem is that when the div loads, instead of showing the page (index.html) in the window from the top – it jumps to the top of the div content. I need the window to load fully so that it looks as if the top & side frames/tables appear to stay the same and only the information in the div changes.

Please help.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@etylocusOct 25.2006 — Can you please post the code of your pages?

If not, how are you loading your pages? Are you using Frames?

If so, what are the names of the frames?
Copy linkTweet thisAlerts:
@salseraauthorOct 25.2006 — Here is the code for "index.html"
[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>[/CODE]


The the working link to request a particular div within that page:
[CODE]<a href="javascript:showHide('#db')"; class="ms_leftnav" onClick="Show('db');">DIV TITLE DB HERE</a><br>[/CODE]

Links to:
[CODE]<div class="section" id="db" ><br>
<span class="style7">DIV TITLE DB HERE</span>
<p>Text Inside of the db div </p></div>[/CODE]


So - I need to call (from page2.html) upon clicking a text link to open "index.html" in the same window (self) and load the specific div (in this case "#db" - but not load the page with the div content at the top - but with the full page in view.

Here's the code for "page2.html"
[CODE]<script type="text/javascript">
function showHide(objID) {
var obj=document.getElementById(objID);
obj.style.display=(obj.style.display=='none')? '' : 'none';
return false;
}
</script>[/CODE]


And the textlink on "page2.html" to request "index.html" and a particular div within that page:

tried this:
[CODE]<a href="javascript:self.location.replace('index.html?showHide=#db')"; class="ms_leftnav" onClick="Show('db');">LINK TITLE HERE</a><br>
[/CODE]


This loads the page properly - but doesn't show the proper div.

also tried this:
[CODE]<a href="index.html" "target=_top"; javascript:showHide('#db')">LINK TITLE HERE</a><br>
[/CODE]

This loads the page and shows the proper div - but drops the page down to the beginning of the div content instead of showing the full page.

also tried this:
[CODE]<a href="index.html" onClick="Show('#db')"; class="ms_leftnav" >LINK TIT HERE</a><br>[/CODE]
This works the same as the try above.

I also tried a lot of other things that just didn't work at all...I'm completely lost here - any help is appreciated.
×

Success!

Help @salsera 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.18,
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,
)...