Solved

Redirecting a web page based on screen resolution

Posted on 2011-09-15
4
414 Views
Last Modified: 2012-05-12
I am a novice with javascript. There is a script at http://www.dynamicdrive.com/dynamicindex9/info3.htm which will redirect a web page based on the screen resolution of the system which is accessing the page.  Instead of redirecting based on a specified width and height, can this script be adapted to redirect based on a range of width?  For example, if the width is between 1024 and 1280 pixels, then a certain URL is targeted; otherwise a different URl is targeted.  Thanks!
0
Comment
Question by:ddantes
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
Ramkisan Jagtap earned 250 total points
ID: 36541662
Hi,
You can try below.
if (screen.width>=1024 && screen.width<=1280 ) //if width is between 1024 anbd 1280
        window.location.replace("http://www.dynamicdrive.com");

Regards,
Ram
0
 

Assisted Solution

by:killer_17
killer_17 earned 250 total points
ID: 36541709
Something like this?

<script type="text/javascript">
function loadPage() {
    if (screen.width >=800 && screen.width <= 1023) // width 800 - 1023 
        window.location ="http://www.netscape.com";	
    else if (screen.width >=1024 && screen.width <=1280) // width 1024 - 1280
        window.location = "http://www.microsoft.com";	
    else // width all else
        window.location = "http://freewarejava.com"; 
}
</script>
<body onload="loadPage();" />

Open in new window


Of course your if-else statements will depend on the ranges you want and their respective target locations.
0
 

Author Comment

by:ddantes
ID: 36544678
Thank you for your comment.  The code performs the redirection just as I hoped!   However, the code appears on the screen momentarily before the redirect.  Is there a way to prevent that artifact?
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 36547292
I think it will not be prevented as you are accessing you first page and then it is redirected to your expected page so it will require some time to execute first page. It will again depends on your internet speed.


Regards,
Ramkisan
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to deal with the query string 8 38
Button function on table is in trouble 3 22
How do I show metrics with PHP or Javascript 6 34
javascript - insert into js doc help 2 25
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question