/    Sign up×
Community /Pin to ProfileBookmark

Load new page and run a function on it

Hi all!
I have a function that first looks if we are on the correct page (defined in the first argument). If we are, I hide all <div>s and show the <div> defined in the other argument. All of that works fine!

But if we are on the incorrect page, I change the location.href (1st arg) and then I want to hide/show <div>s on the loaded page, as I do above. The page loads fine and I can see the correct <div> show a fraction of a second but then it disappears.

Is it something with the onload or…? Thanks!

function openInternal(page,area) {

. //Get file name
. fileName = getFileName(location.href, “/”);
. if (fileName.indexOf(page) != -1) {
. . // On the right page, now hide/show div!
. . showActivity(area);
. } else { // Wrong page, load other page
. . window.location.href = “basics.”+page+”.html”;
. . checkLoad(area);
. }
}

function getFileName(fullString, subString) {
. if (fullString.lastIndexOf(subString) == -1) {
. . return “”;
. } else {
. . return fullString.substring(fullString.lastIndexOf(subString)+1, fullString.length);
. }
}

function checkLoad(area) {
. if (window.onLoad) {
. . showActivity(area);
. } else {
. . setTimeout(“checkLoad(area);”, 100)
. }
}

function showActivity(area) {
. var allDivs = document.getElementsByTagName(“div”);
. for (i=0; i<allDivs.length; i++) {
. . if (allDivs[i].className == “activityContainer” ¦¦ allDivs[i].className == “introduction”) {
. . . allDivs[i].style.display = ‘none’;
. . }
. }
. document.getElementById(area).style.display = “block”;
}

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@MrNobodyNov 06.2008 — You need to pass an argument on this line to tell the page what you want done:

window.location.href = "basics."+page+".html";

such as:

window.location.href = "basics."+page+".html?area="+area;

Then, you have to extract that argument from the [B]self.location.search[/B] property after the page loads.
×

Success!

Help @claes 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...