Click to See Complete Forum and Search --> : check window size then redirect??


+-=E-Rawk=-+
04-11-2003, 06:54 PM
Ok, heres what im trying to do... I want the script to check the window size and if it isnt eaxctly 750x550 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


<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>

Jona
04-11-2003, 06:57 PM
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.

Jona
04-11-2003, 07:04 PM
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>

+-=E-Rawk=-+
04-11-2003, 07:07 PM
but i dont want it to be a button....
I tried it like this...
<HTML>
<HEAD>
<script language="JavaScript"><!--
function checkSize() {
w = window.innerWidth;
h = window.innerHeight;
if ((w != '750') || (h != '550')){
location= 'index.html';
}
//--></script>
</HEAD>
<BODY onLoad="checkSize()">
</BODY>
</HTML>
Cause its still not workin!:confused: Where is the html wrong there?

Jona
04-11-2003, 07:10 PM
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.

+-=E-Rawk=-+
04-11-2003, 07:19 PM
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!

+-=E-Rawk=-+
04-11-2003, 07:47 PM
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?

Jona
04-11-2003, 07:49 PM
Post the whole code you're using. Make sure your JavaScript is in the <head> tags.

+-=E-Rawk=-+
04-11-2003, 08:13 PM
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.

Jona
04-11-2003, 08:15 PM
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.