Solved

Redirecting a web page based on screen resolution

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now