/    Sign up×
Community /Pin to ProfileBookmark

check window size then redirect??

Ok, heres what im trying to do… I want the script to check the window size and if it isnt eaxctly 750×550 i want it to send the user back to the front page (/index.html). So basicly i just wanna say… “if the width doesnt equal 750 or the height doesnt equal 550; send the user to index.html.” I know this code below isnt right but its all i could gather :p

[CODE]<HTML>
<HEAD>
<body bgcolor=”black”>
<script language=”JavaScript”><!–

function checkSize(w,h) {

w = window.innerWidth;
h = window.innerHeight;

if ((w != ‘750’) || (h != ‘550’)){
parent.location.href= ‘index.html’;
}

//–></script>
</HEAD>
<BODY onLoad=”checkSize()”>
</BODY>
</HTML>[/CODE]

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@JonaApr 11.2003 — You don't need the checkSize(w,d) in there. Just checkSize() is fine, but either works. You don't need parent.location.href, location or location.href works fine.
Copy linkTweet thisAlerts:
@JonaApr 12.2003 — BTW, you might want to finish learning HTML before going on to JavaScript. Your HTML was wrong, too:

<HTML>

<HEAD>

<script language="JavaScript">

function checkSize() {

w = screen.width;

h = screen.height;

if((w != '750') && (h != '550')){

location.href='index.html';

}

else { alert("nope"); }

}

</script>

</head>

<BODY bgcolor="black">

<input type=button value="CheckSize" onClick="checkSize()">

</BODY>

</HTML>
Copy linkTweet thisAlerts:
@_-_E-Rawk_-_authorApr 12.2003 — but i dont want it to be a button....

I tried it like this...
&lt;HTML&gt;
&lt;HEAD&gt;
&lt;script language="JavaScript"&gt;&lt;!--
function checkSize() {
w = window.innerWidth;
h = window.innerHeight;
if ((w != '750') || (h != '550')){
location= 'index.html';
}
//--&gt;&lt;/script&gt;
&lt;/HEAD&gt;
&lt;BODY onLoad="checkSize()"&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;

Cause its still not workin!? Where is the html wrong there?
Copy linkTweet thisAlerts:
@JonaApr 12.2003 — Well, I don't think it makes too much of a difference, but you're using the OR operator (||) instead of what I used, which is the AND operator (&&). Make sure your screen resolution isn't 750x550. Also, you're using window.innerWidth and window.innerHeight. I changed that, too. It should be screen.width and screen.height. Your original HTML was wrong because you had two body tags (one of which was not closed) and the first of which was inside the head tags.
Copy linkTweet thisAlerts:
@_-_E-Rawk_-_authorApr 12.2003 — ohhh okay great. Thanks for your help. I defenitly need to learn some more javascript. I know my HTML though, that was just a copy and paste thing. Again, thanks for the response im truly greatful!
Copy linkTweet thisAlerts:
@_-_E-Rawk_-_authorApr 12.2003 — hmmmm, if i place a flash movie in the html document the javascript stops working, even when placed in the right spot. If i comment out the flash part of the HTML then the script starts working again. Is it possible to run them both in the same html document? Any idea what i might be running into?
Copy linkTweet thisAlerts:
@JonaApr 12.2003 — Post the whole code you're using. Make sure your JavaScript is in the <head> tags.
Copy linkTweet thisAlerts:
@_-_E-Rawk_-_authorApr 12.2003 — ohh i guess it looks for the flash movie before it will run the javascript so if it cant find the movie the script wont run.

Is it possible to change my statement to say "if the browser toolbar=yes; send the user to index.html."

Cause the width x height size thing might cause errors in the longrun but basicly i want to redirect to the front page if the browser isnt reconfigured the way i like.
Copy linkTweet thisAlerts:
@JonaApr 12.2003 — Nope, you can't check to see if the toolbar exists. You can, though, close the current window and open a new window with the configurations you want.
×

Success!

Help @_-_E-Rawk_-_ 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.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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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