Important alert: (current site time 7/15/2013 12:22:02 PM EDT)
 

VB icon

A Screen Size Redirection With Variable Passed Back To Server

Email
Submitted on: 11/29/2001 1:15:45 AM
By: Brian Reeves 
Level: Intermediate
User Rating: By 1 Users
Compatibility: JavaScript
Views: 16454
(About the author)
 
     Screen Size and Browser sniffer that talks to the server... I actually use this little snippet cause I needed to get the window size (not resolution), and browser information to the server asp code to be able to create the resulting page strictly for the browser / resolution.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: A Screen Size Redirection With Variable Passed Back To Server
' Description:Screen Size and Browser sniffer that talks to the server... I actually use this little snippet cause I needed to get the window size (not resolution), and browser information to the server asp code to be able to create the resulting page strictly for the browser / resolution.
' By: Brian Reeves
'
' Returns:appends an .asp variable to the redirected page.
Such as "http://www.url.com/default.asp?b=xxxx
'
' Assumes:This code was designed with asp just replace all of the '<%= VariableName %> with the location... I use this as a ssi on certain pages.
'
' Side Effects:It does a client side redirect so you show up as redirection on search engines...
This is what i use if you want to redirect to different pages you should be able to figure it out if you need any help i will add to it.
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=2496&lngWId=14'for details.'**************************************

<%
'This code was written by Brian Reeves (ketapillar 'at' hotmail 'dot' com)
'If you want to use this code go ahead just make some note in the comments
'referencing that i coded it.
Dim strURL, strDocument, strDescription, strKeywords, strTitle
' Below is for setting the variables in real life I use a database
'to populate these fields.
strURL = "http://www.url.com/" 'remember the slash
' could leave bland if you are in the same directory example below
' strURL = ""
strDocument = "pagename.asp"'name of the page
strDescription = "This is the page description"
strKeywords = "this, is, a, listing, of, the, keywords, for, this, page"
strTitle = "This Pages Title"
' 
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<meta name="Description" content="<%= strDescription%>">
<meta name="Keywords" content="<%= strKeywords %>">
<title><%= strTitle %></title>
</head>
<body title="<%= strBodyTitle %>">
<script language="JavaScript" type="text/javascript">
	/*******************************************************
	Resolution Redirection JavaScript. Is supported in ie3+,
	and ns3+ All of the code was rewritten from examples that
	i have no idea where they came from.
	
	Author: Brian Reeves
	Email:ketapillar@hotmail.com
	********************************************************/
		breakFrames();
		
		var strNewLocation="";					// Used as placeholder
		var strURL="<%= strURL %>"; 			// URL of redirect document
		var strDocument="<%= strDocument %>";	// Name of redirect document
		
		var strBrowser = getBrowser();
		var strResolution = getResolution();
	
		strNewLocation=strURL + strDocument + "?b=" + strBrowser + strResolution;
		if((strBrowser == "ie5") || (strBrowser == "ie4") || (strBrowser == "ie3") || (strBrowser == "ns4"))
			{document.location.href=strNewLocation;}		//	Redirecting
		else {document.location.href="oldsite/index.html";}	// Redirecting to oldsite
	/********************************************************
	variable getResolution();
	Gets the clients available screen width and returns the 
	width in "a,b,c,d or e" depending on the resolution. 
	Will return "z" on unsupported resolutions.
	Possible future modifications could be if both are null,
	open a new browser window "full screen" write an image
	100% x 100% get the image size and return the values.
	********************************************************/
	function getResolution(){
		var iWidth, iHeight, sRes;
		if (window.innerWidth != null) {
			iWidth = window.innerWidth;
			iHeight = window.innerHeight; 
		}
		else if (document.body.clientWidth != null) {
			iWidth = document.body.clientWidth;
			iHeight=document.body.clientHeight;
		}
		else { iWidth = 640; }
		if(iWidth <= 640) 
			{sRes = "a";}		// 640 x 480 Resolution
		else if(iWidth <= 800)
			{sRes = "b";}		// 800 x 600 Resolution
		else if(iWidth <= 1024)
			{sRes = "c";}		// 1024 x 800 Resolution
		else if(iWidth <= 1280)
			{sRes = "d";}		// 1280 x 1024 Resolution
		else if(iWidth <= 1600)
			{sRes = "e";}		// 1600 x 1200 Resolution
		else {sRes = "z"}
		return (sRes);
	}
	/********************************************************
	getBrowser();
	Gets the users browser type and returns "ie5, ie4, ie3, 
	ns6, ns4, ns3". Will return "other" on any other browser.
	********************************************************/
	function getBrowser() {
		var vBrowser=navigator.appName;			
		var vVersion=navigator.appVersion;
		var sBrowser;
		if (vBrowser.indexOf("Microsoft")>=0 && vVersion.indexOf("6")>=0)
			{sBrowser="ie5";} 	// Microsoft Internet Explorer 5.x
		else if (vBrowser.indexOf("Microsoft")>=0 && vVersion.indexOf("5")>=0)
			{sBrowser="ie5";} 	// Microsoft Internet Explorer 5.x
		else if (vBrowser.indexOf("Microsoft")>=0 && vVersion.indexOf("4")>=0)
			{sBrowser="ie4";}		// Microsoft Internet Explorer 4.x
		else if (vBrowser.indexOf("Microsoft")>=0 && vVersion.indexOf("3")>=0)
			{sBrowser="ie3";}	// Microsoft Internet Explorer 3.x
		else if (vBrowser.indexOf("Netscape")>=0 && vVersion.indexOf("6")>=0)
			{sBrowser="ns6";}	// Netscape Navigator 6.x
		else if (vBrowser.indexOf("Netscape")>=0 && vVersion.indexOf("4")>=0)
			{sBrowser="ns4";}	// Netscape Navigator 4.x
		else if (vBrowser.indexOf("Netscape")>=0 && vVersion.indexOf("3")>=0)
			{sBrowser="ns3";}	// Netscape Navigator 3.x
		else
			{sBrowser="other";}	// All Others 	
		return(sBrowser);
	}	
	/********************************************************
	breakFrames();
	breakFrames() Tests if user was linked to here within
	a frame. If true then will reopen current location
	in the parent window.
	********************************************************/
	function breakFrames(){
		if(self.parent.frames.length != 0)
			{self.parent.location = document.location;}
	}
	
</script>
<!-- Page to show to search engines and browsers that do not support javascript -->
</body>
</html>


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

3/20/2003 4:10:49 PMJoe Peres JAVA JOE

For a person not knowing javascript your code is hard to understand and needs more spcific commenting
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.