Don't show page if onLoad event takes page elsewhere

I have this code:
<body onLoad="save_proj(); chk_ems(); set_pointers(); chk_skip_summ();">

Open in new window

and this:
function chk_skip_summ() {
	if (nosumm == "1") {
		window.location = "send_email_ls250.php?ddocs=" + ddocs;
	}	
}

Open in new window


Of course the page it is on loads, then the page send_mail_ls250.php loads if nosumm is "1".

The customer does not like the first page flashing up, then disappearing.

Is there a way I can do this so the first page does not show AT ALL?

Thanks
Richard KortsBusiness Owner / Chief DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zephyr_hex (Megan)DeveloperCommented:
Wrap all of your content in an element like a div, and set that div to invisible.  Then, if the page does not redirect, set it to visible.

Demo: https://jsfiddle.net/zephyr_hex/fwmsd83m/

<body onLoad="save_proj(); chk_ems(); set_pointers(); chk_skip_summ();">
   <div id="container" style="visibility: hidden;">
     //content here
   </div>
</body>

Open in new window


function chk_skip_summ() {
	if (nosumm == "1") {
		window.location = "send_email_ls250.php?ddocs=" + ddocs;
	}
        //show body
        document.getElementById("container").style.visibility = 'visible';
}

Open in new window

0
Dave BaldwinFixer of ProblemsCommented:
Something like Megan suggested would be necessary... because 'onload' means after the page has loaded.
0
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
Does not seem to work.

Top <body> code now looks like this:
<body onLoad="chk_skip_summ(); save_proj(); chk_ems(); set_pointers(); chk_skip_summ();">
<div id="container" style="visibility: hidden;"> 

Open in new window


chk_skip_summ() looks like this:
function chk_skip_summ() {
	if (nosumm == "1") {
		window.location = "send_email_ls250.php?ddocs=" + ddocs;
	}	
	//show body
    document.getElementById("container").style.visibility = 'visible';
}

Open in new window


There is no other element on the page with id of container.

If you send me a private emai, I can email you a login & password & steps to reproduce.

Thanks

Richard
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Dave BaldwinFixer of ProblemsCommented:
The method works but there may be something wrong with your logic.  Here's a simple test program you can play around with.  You might want to use 'display' instead of 'visibility'.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Onload Test</title>
<script type="text/javascript">
<!--
function makevisible() {
	document.getElementById("container1").style.visibility = 'visible';
	document.getElementById("container2").style.visibility = 'hidden';
	document.getElementById("container3").style.display = 'inline';
	document.getElementById("container4").style.display = 'none';
	}
// -->
</script>
</head>
<body onload="makevisible();">
<p>The first 'div' below should be visible after the page is loaded and the second 'div' should be hidden.</p>
<div id="container1"  style="visibility: hidden;">This is the first 'div'.</div>
<div id="container2"  style="visibility: visible;">This is the second 'div'.</div>
<p>The third 'div' below should be visible after the page is loaded and the fourth 'div' should be hidden.</p>
<div id="container3"  style="display: none;">This is the third 'div'.</div>
<div id="container4"  style="display: inline;">This is the fourth 'div'.</div>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
Dave,

All that works fine.

It seems there is some problem with timing.  I changed the Javascript function to:
function chk_skip_summ() {
	alert("nosumm = " + nosumm);
}

Open in new window

Removing the window.location = "send_email_ls250.php?ddocs=" + ddocs;

The page is blank (after the alert is answered).

Then I changed the function to:

function chk_skip_summ() {
	alert("nosumm = " + nosumm);
        document.getElementById("container").style.visibility = 'visible';
}

Open in new window


Then the page displays after the alert is answered.

It looks like there is a pause before the window.location is executed.

I am thinking that the fact there are 4 functions referenced in the onLoad makes it execute the other 3 (with visibility on) BEFORE the window.location is executed.

Does that make sense?

Thanks,

Richard
0
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
I got it to work.

I removed the function chk_skip_summ() from the onLoad action.

At the VERY end of the body, after the body tag, I put in this Javascript:

</body>
<script>
	if (nosumm == "1") {
		window.location = "send_email_ls250.php?ddocs=" + ddocs;
	} else {
		document.getElementById("container").style.visibility = 'visible';
	}	
</script>

Open in new window


It goes to the other php WITHOUT flashing the page image first.

Richard
1
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
Thanks for pointing out the use of visible & hidden; I ultimately used that.

I still don;t see why the doesn't work as part of onLoad, but a solution that works is what I needed.

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.