 |
Javascript How-To Ask your "How do I do this with Javascript?" questions here. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

June 29th, 2004, 09:08 AM
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Alert when page opens?
I found the following code that does what I want, except I would like the alert to open when the page is loaded instead of having to click on a link after the page loads.
<A HREF="javascript:alert('Your resolution is '+screen.width+'x'+screen.height);">
Click for your screen resolution</A>
Can someone give me a hand with this? Sure would appreciate it :)
Rudy
__________________
Rudy
|

June 29th, 2004, 09:18 AM
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Larry,
Try putting this in the body tag of your HTML page:
<BODY onload ="javascript:alert('your message here')">
HTH
interrupt
|

June 29th, 2004, 09:30 AM
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorry Larry
I didn't even read that properly, sorry, my bad. Here's what you should do:
Between your head tags:
<head>
<script language ="javascript">
function myFunction(){
alert('Your resolution is '+screen.width+'x'+screen.height);
}
</script>
</head>
In your body tag:
<body onload = "myFunction()">
</html>
HTH
interrupt
|

June 29th, 2004, 09:55 AM
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks HTH that last reply is just what I asked for. Have one more request that may be a bit of a chalenge.
I would like the alert to open when the page opens showing the screen size of the user, but instead of a simple alert I would like to use a confirm alert using several (if else) statements.
If the confirm alert indicates that their screen size is 800x600, they could click "Cancel" which would simply close the page or they could click "OK" and then be directed to another web page. I would like "if" statments and a URL for each screen resolution such as the following: 800x600, 1024x768, 1280x1024,1600x122.
I know what I need, just don't know enough about javascript to write the code. Would you be so kind as to help me again with this?
Rudy
|

June 29th, 2004, 10:24 AM
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
So you want something like this?
<script language=javascript type='text/javascript'>
function screenPrompts()
{
if(screen.width == 800 && screen.height == 600)
{
(confirm('You are 800x600, continue?')) location.replace("800x600.asp") : closeWindow();
}
else if(screen.width == 1024 && screen.height == 768)
{
(confirm('You are 1024x768, continue?')) location.replace("1024x768.asp"):closeWindow();
}
//other if/else if statements.....
}
onload = function(){myFunction;}; //set the onload
</script>
HTH,
Snib
<><
|

June 29th, 2004, 10:54 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
quote:Thanks HTH that last reply is just what I asked for.
|
LOL.
HTH means Hope this Helps.... ;)
HtH,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: No Girl So Sweet by P.J. Harvey (Track 11 from the album: Is This Desire?) What's This?
|

June 29th, 2004, 10:57 AM
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
LOL.... I've had that happen on other forums.... :-)
Snib
<><
|

June 29th, 2004, 11:14 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Besides the technical implications and solutions of your request, I am interested why you'd want a solution like this.
It seems that you are designing site for multiple resolutions. IMO, that's not a wise thing to do, as it will force you to create the same site at least three or 4 times. I sometimes run my screen at 2048 by 1536 here, do I get my own version? Probably not.
If I were you, I'd try to design a site that flows with whatever monitor the user has. Terms like liquid design are often associated with this concept. This means that specific areas of your site can have a fixed width (like a menu) while the content area flows with the width of the browser. site. At extreme high resolutions you may end up with an odd looking site, so you could restrict to width to a certain maximum width. This way, the site will look good on all kinds of monitors.
The good thing about this is that it will work with "old skool" HTML (i.e. tables) and modern ways of Web development: CSS. But the biggest benefit is that you only have to design, create *and* maintain one single page. No need to fix a bug or change a design in all your different resolution pages.
Just my 2 cents......
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: A Dream by Lou Reed & John Cale (Track 13 from the album: Songs For Drella) What's This?
|

June 29th, 2004, 11:20 AM
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Yes, in agreement with Imar, redesigning the site 4, 5+ times is not a good idea, especially if it is constantly updated. Frames, tables and <div>s are all compatible with '%' widths, which is what you would likely be using.
But if you have some special reason to make it like you are, is the given code what you're looking for?
Snib
<><
|

June 29th, 2004, 01:03 PM
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yes, I have recreated the same Web page at different screen resolutions with a redirect script depending upon the resolution found. Yes, its a real pain but I have never been able to figure out how to make my web site fit any screen size.
Any help would be appreciated :)
Quote:
quote:Originally posted by Imar
Besides the technical implications and solutions of your request, I am interested why you'd want a solution like this.
It seems that you are designing site for multiple resolutions. IMO, that's not a wise thing to do, as it will force you to create the same site at least three or 4 times. I sometimes run my screen at 2048 by 1536 here, do I get my own version? Probably not.
If I were you, I'd try to design a site that flows with whatever monitor the user has. Terms like liquid design are often associated with this concept. This means that specific areas of your site can have a fixed width (like a menu) while the content area flows with the width of the browser. site. At extreme high resolutions you may end up with an odd looking site, so you could restrict to width to a certain maximum width. This way, the site will look good on all kinds of monitors.
The good thing about this is that it will work with "old skool" HTML (i.e. tables) and modern ways of Web development: CSS. But the biggest benefit is that you only have to design, create *and* maintain one single page. No need to fix a bug or change a design in all your different resolution pages.
Just my 2 cents......
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: A Dream by Lou Reed & John Cale (Track 13 from the album: Songs For Drella) What's This?
|
Rudy
|
|
 |