/    Sign up×
Community /Pin to ProfileBookmark

If, Else Statement

To start off I’m a pretty novice javascript user, so here’s my problem. The website I’m working on has a frame to the left that lists a series of links that go to different “home” webpages. The frame on the left and a frame on the top stay on the page while the “home” pages load to the right of the page like this


___________________________

| Top Frame
|__________________________
| page 1 |
| page 2 |
| page 3 | Webpage loads here
| page 4 |
| page 5 |
| page 6 |

I have set a popup page to come up when, for instance “page 5”, is clicked on. This popup shows up and tells the user some information. At the bottom of the popup window there is a button that when pressed creates a cookie that causes the popup to not show again. What I want is that when the next time the user goes and clicks on page 5, if they have the cookie, it just loads the page to the right as if the popup never existed. I have an “if, else” statement that checks if the user has the cookie then either loads the popup or loads the webpage. The only problem I’m having is that I can’t figure out how to just have the page load and not appear in a new window. Here is my javascript code by itself in a new .htm for test purposes.

<html>

<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=windows-1252″>
<title>Javascript Test</title>
<meta name=”Microsoft Theme” content=”newsitetheme 1011, default”>

<script language=”javascript”>

var expDate = new Date();
expDate.setTime(expDate.getTime()+365*24*60*60*1000); // one year

function setCookie(isName,isValue,dExpires){
document.cookie = isName+”=”+isValue+”;expires=”+dExpires.toGMTString();
}

function getCookie(isName){
cookieStr = document.cookie;
startSlice = cookieStr.indexOf(isName+”=”);
if (startSlice == -1){return false}
endSlice = cookieStr.indexOf(“;”,startSlice+1)
if (endSlice == -1){endSlice = cookieStr.length}
isData = cookieStr.substring(startSlice,endSlice)
isValue = isData.substring(isData.indexOf(“=”)+1,isData.length);
return isValue;
}

function Popup(){

if (!getCookie(‘pop1’))
{popWin1 = window.open(“PopUp.htm”,””,”scrollbars=yes”,”width=850,height=1700,top=400,left=500″)}
else {window.open=”page 5.htm”} //using page 5 as an example I’m using window.open but I want it to just load the page not popup

}

</script>

</head>

<body>

<p style=”margin-top: 0; margin-bottom: 1px” align=”center”>
<img border=”0″ src=”Button.gif” width=”86″ height=”70″ id=”Home” onclick=”Popup()”></p>

</body>

</html>

And this is added to the PopUp.htm page

<input type=button value=”Don’t show again” onclick=”opener.setCookie(‘pop1’,0,opener.expDate);self.close()”>

along with the javascript functions above. Sorry if this is confusing its hard not to be. ?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@smokeybill08authorJun 25.2009 — Sorry it should be,

window.open("page 5.htm") not window.open="page 5.htm"

The problem still remains though. ?
Copy linkTweet thisAlerts:
@smokeybill08authorJun 25.2009 — I think I've solved it but using

window.location.href="page 5.htm";

instead of

window.open("page 5.htm");

I works now. Thanks! ?
×

Success!

Help @smokeybill08 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.2,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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