Solved

Redirecting a web page based on screen resolution

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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 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…

758 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

22 Experts available now in Live!

Get 1:1 Help Now