Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Redirecting a web page based on screen resolution

Posted on 2011-09-15
4
Medium Priority
?
437 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
Ramkisan Jagtap earned 1000 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

661 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