Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 29th, 2004, 09:08 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #2 (permalink)  
Old June 29th, 2004, 09:18 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Larry,

Try putting this in the body tag of your HTML page:

<BODY onload ="javascript:alert('your message here')">

HTH
interrupt



Reply With Quote
  #3 (permalink)  
Old June 29th, 2004, 09:30 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #4 (permalink)  
Old June 29th, 2004, 09:55 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #5 (permalink)  
Old June 29th, 2004, 10:24 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

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

<><
Reply With Quote
  #6 (permalink)  
Old June 29th, 2004, 10:54 AM
Imar's Avatar
Wrox Author
Points: 72,022, Level: 100
Points: 72,022, Level: 100 Points: 72,022, Level: 100 Points: 72,022, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,076
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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?
Reply With Quote
  #7 (permalink)  
Old June 29th, 2004, 10:57 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

LOL.... I've had that happen on other forums.... :-)

Snib

<><
Reply With Quote
  #8 (permalink)  
Old June 29th, 2004, 11:14 AM
Imar's Avatar
Wrox Author
Points: 72,022, Level: 100
Points: 72,022, Level: 100 Points: 72,022, Level: 100 Points: 72,022, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,076
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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?
Reply With Quote
  #9 (permalink)  
Old June 29th, 2004, 11:20 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

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

<><
Reply With Quote
  #10 (permalink)  
Old June 29th, 2004, 01:03 PM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirecting Page With Alert arnabghosh Classic ASP Professional 0 November 8th, 2007 02:43 AM
Button that opens an image comicghozt Access 6 June 3rd, 2006 02:29 AM
drop down list opens dynamically when page loads robear Javascript How-To 5 April 21st, 2006 10:05 AM
Alert Shows On Page Load Ben Horne Javascript How-To 3 April 6th, 2004 04:30 PM
page download alert sirsyme Classic ASP Basics 0 July 15th, 2003 09:07 AM



All times are GMT -4. The time now is 01:51 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.