javascript alert problem

J

Jorntk

<script language="JavaScript">
!--
function onLoad()
{
if( self.innerWidth < 1024 )
{
self.moveTo( 0, 0 );
self.resizeTo( screen.availWidth, screen.availHeight );
}

if( self.innerWidth < 1024 )
{
alert( "This Web page was designed to be viewed using a" + " screen
resolution of 1024x768 or larger." );
}
}

Why thus code is not working when my screen resolution is 800*600? Please
Help!!
 
E

Evertjan.

Jorntk wrote on 04 mei 2004 in comp.lang.javascript:
<script language="JavaScript">
!--
function onLoad()
{
if( self.innerWidth < 1024 )
{
self.moveTo( 0, 0 );
self.resizeTo( screen.availWidth, screen.availHeight );
}

if( self.innerWidth < 1024 )
{
alert( "This Web page was designed to be viewed using a" + " screen
resolution of 1024x768 or larger." );
}
}

dit you try this [oonly this code in a html-file:

<body onload="alert(self.innerWidth)">

??

undefined

==================

Now try:

<body onload="alert(screen.availWidth)">

See:
<http://msdn.microsoft.com/workshop/
author/dhtml/reference/dhtml_reference_entry.asp>

and perhaps also:
<http://msdn.microsoft.com/workshop/author/om/measuring.asp>

because client users more often than not do not want full screen
 
I

Ivo

Ok, it work now. But i got new problem.
I put the alert in a header.php where i will call the header.php everytime.
This cause the alert pop up when I click every button to view new page.
So, is there anyway to limit the alert to only pop up for one time??
Please advice. Thanx!

The usual way to do this is with a cookie or something serverside like a
session variable. There is no other way of knowing the difference between
first time visitors and those going to the next page.
But also to be considered: There might be a lot people going to the next
page if you leave it up to them to resize their window. And unless you have
something very special to show, you should not design for any specific
screen resolution at all. Most users do not even know how to change their
resolution (assuming, against better judgement, they would be willing to go
through of trouble of doing so only to see your site) so the javascript will
do nothing but annoy people.
HTH
Ivo
 
M

Michael Winter

Ok, it work now. But i got new problem.
I put the alert in a header.php where i will call the header.php
everytime.
This cause the alert pop up when I click every button to view new page.
So, is there anyway to limit the alert to only pop up for one time??
Please advice. Thanx!

Frankly, you shouldn't do it at any time. The users don't know or care
what it was designed for. After all, their resolution will, more than
likely, be set to the optimal value anyway, so what good will it do? Sites
for the World Wide Web should use liquid design so it doesn't matter
(within reason) what the resolution is, large or small. Finally, screen
resolution means practially nothing. It's set to 1024x768 on this machine,
but you'll only get 866x582 to work with once you remove toolbars,
sidebars, and the like.

One final point, you do realise that statistics (unreliable as they are)
show the majority of users use 800x600, don't you?

Mike
 
K

kaeli

[email protected] enlightened us said:
<script language="JavaScript">
!--
function onLoad()
{
if( self.innerWidth < 1024 )
{
self.moveTo( 0, 0 );
self.resizeTo( screen.availWidth, screen.availHeight );

Um, you do know that us Opera and Mozilla users can disable that
nonsense, right?
You have no right to resize or move MY windows. Sorry.
}

if( self.innerWidth < 1024 )
{
alert( "This Web page was designed to be viewed using a" + " screen
resolution of 1024x768 or larger." );

I guess I won't be using your page. Neither will most people. The
majority of users use 800 by 600. And an alert? How annoying. I can
read. If you want to tell people that you can't code, just put it on the
page.

Gee, I sure hope disabled people don't need your site, either.

--
 
J

Jorntk

Ok, it work now. But i got new problem.
I put the alert in a header.php where i will call the header.php everytime.
This cause the alert pop up when I click every button to view new page.
So, is there anyway to limit the alert to only pop up for one time??
Please advice. Thanx!
 
G

Grant Wagner

Jorntk said:
Ok, it work now. But i got new problem.
I put the alert in a header.php where i will call the header.php everytime.
This cause the alert pop up when I click every button to view new page.
So, is there anyway to limit the alert to only pop up for one time??
Please advice. Thanx!

You only think you have it working. For starters, "self.innerWidth" returns
"undefined" on Internet Explorer, which is always less then 1024 on Internet
Explorer.

On browsers like Gecko based browsers (Netscape 7.1, Mozilla, Firefox, Camino,
Opera 7.23), where self.innerWidth actually returns typeof "number", even a
user with a 1024 x 768 desktop will be told they aren't running their browser
at 1024 x 768, because window.innerWidth is ALWAYS less then the width of the
applicable desktop (due to borders and scrollbars and any side-docked
toolbars).

Not to mention that in Netscape 7.1, Mozilla and Firefox, browsers where you
are actually able to retrieve self.innerWidth (and make an incorrect assumption
about the size of their browser based on that value), users can disable the
ability for you to move or resize their browser.

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top