Solved

Redirecting a web page based on screen resolution

Posted on 2011-09-15
4
428 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 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…
Suggested Courses

636 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