Forum Moderators: open

Message Too Old, No Replies

Load new page and run a function on it

         

Claes100

8:08 am on Nov 6, 2008 (gmt 0)

10+ Year Member



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 coreect <div> show a fraction of a second but then it disappears.

Is it something with the onload or...? Thanks!

function openInternal(projSize,area) {

. //Get file name
. fileName = getFileName(location.href, "/");
. if (fileName.indexOf(projSize) != -1) {
. . // On the right page, now hide/show div!
. . showActivity(area);
. } else { // Wrong page, load other page
. . window.location.href = "basics."+projSize+".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";
}

caribguy

4:50 pm on Nov 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I hope that you have already found and installed Firebug and Venkman. If you haven't, all you did so far is code in the dark.

Sorry to be a bit of a pedant: if you can avoid it you should probably not use camelCase for functions, variables and element names (it will keep you sane in the long run).