Google Answers Logo
View Question
 
Q: Javascript: Resize window based upon browser type ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Javascript: Resize window based upon browser type
Category: Computers > Programming
Asked by: koalb-ga
List Price: $20.00
Posted: 17 Jan 2003 05:36 PST
Expires: 16 Feb 2003 05:36 PST
Question ID: 144651
I'm looking for a javascript that will resize a browser window's size
automatically as a page loads (not off of a link) depending upon the
browser type. Obviously, I'm looking for something that will
distinguish between IE and NN > 4.0, but I need the js to make account
for other browsers as well. The size of the browser needs to be
defined in pixels, not percentage.

The logic of the js might look something like this:

-On page load
-if browser=IE, then resize window to x1,y1
-if browser=NN, then resize window to x2,y2
-if browser <> IE or NN then resize window to x3,y3.

If it helps, you can study my patchwork solution at:
www.concoctiondesign.com/beta/about/about.html

I'm using DW MX to build this site, and I don't know JS to save my
life, so it needs to be plug and play.

I'll tip $5 for a clean, working piece of js!!
Answer  
Subject: Re: Javascript: Resize window based upon browser type
Answered By: voyager-ga on 17 Jan 2003 07:18 PST
Rated:5 out of 5 stars
 
Hi koalb,

the script you are looking for might look like this one:

<HTML>
<HEAD>
<TITLE> Window Resizing Test </TITLE>

<script language="JavaScript">
<!--

br=navigator.appName;
brversion=parseInt(navigator.appVersion);

x1=100;
y1=100;
x2=200;
y2=200;
x3=300;
y3=300;

if (br=="Netscape" && brversion>=4)
 {
 window.resizeTo(x1,y1);
 alert("Navigator");
 }
else
 {
 if (br=="Microsoft Internet Explorer")
  {
  window.resizeTo(x2,y2);
  alert("IE");
  }
 else
  {
  window.resizeTo(x3,y3);
  alert(br);
  }
 }

//-->
</script>

</HEAD>

<BODY BGCOLOR="#FFFFFF">
<h1>test</h1>
</BODY>

</HTML>

I have included a link in the additional sources section that shows
how exactly you can detect other browsers than the ones you asked in
your question. I have also added alerts, so you can see that the
browser detection works correctly.

I hope this helps. If you have any problems with the script or require
additional information, feel free to request a clarification at any
time.


voyager-ga

Additional Sources

The Ultimate JavaScript Client Sniffer, Version 3.03:
http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html

Search Strategy

resize window javascript
://www.google.com/search?sourceid=navclient&q=resize+window+javascript

javascript browser version
://www.google.com/search?hl=en&lr=&ie=ISO-8859-1&q=javascript+browser+version

Request for Answer Clarification by koalb-ga on 17 Jan 2003 08:45 PST
Thanks! It worked great!

I'm using this with Dreamweaver's wysiwyg java plugins and was just
curious to know if I've "integrated" your js as
efficiently/effectively as possible. Remember, I know just enough to
be dangerous.









<script language="JavaScript" type="text/JavaScript">
<!--
//tmtC_Resize_Window
br=navigator.appName; 
brversion=parseInt(navigator.appVersion); 

if (br=="Netscape" && brversion>=4) 
 { 
 window.resizeTo(800,600);  
 } 
else 
 { 
 if (br=="Microsoft Internet Explorer") 
  { 
  window.resizeTo(822,634);  
  } 
 else 
  { 
  window.resizeTo(800,600);  
  } 
 } //tmtC_Resize_WindowEnd
 
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0;
i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image;
d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr;
for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array;
for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc)
x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
</script>

Request for Answer Clarification by koalb-ga on 17 Jan 2003 15:10 PST
Thanks! It worked great! 
 
I'm using this with Dreamweaver's wysiwyg java plugins and was just
curious to know if I've "integrated" your js as
efficiently/effectively as possible. Remember, I know just enough to
be dangerous.
 
 
 
 
 
 
 
 
 
<script language="JavaScript" type="text/JavaScript"> 
<!-- 
//tmtC_Resize_Window 
br=navigator.appName;  
brversion=parseInt(navigator.appVersion);  
 
if (br=="Netscape" && brversion>=4)  
 {  
 window.resizeTo(800,600);   
 }  
else  
 {  
 if (br=="Microsoft Internet Explorer")  
  {  
  window.resizeTo(822,634);   
  }  
 else  
  {  
  window.resizeTo(800,600);   
  }  
 } //tmtC_Resize_WindowEnd 
  
function MM_preloadImages() { //v3.0 
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); 
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0;
i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image;
d.MM_p[j++].src=a[i];}}
} 
 
function MM_swapImgRestore() { //v3.0 
  var i,x,a=document.MM_sr;
for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
} 
 
function MM_findObj(n, d) { //v4.01 
  var p,i,x;  if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} 
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x; 
} 
 
function MM_swapImage() { //v3.0 
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array;
for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc)
x.oSrc=x.src; x.src=a[i+2];}
} 
 
function MM_openBrWindow(theURL,winName,features) { //v2.0 
  window.open(theURL,winName,features); 
} 
//--> 
</script>

Clarification of Answer by voyager-ga on 17 Jan 2003 17:05 PST
Hi koalb,

thank you for the good rating and the tip! As to the way you
integrated the javascript into your page - that's fine. You basically
can't do anything wrong as long as you leave the part fairly at the
top of the <head> section, so it's among the first things that happen.
That way you won't have the resizing interfere with anything that you
might want to do later on in the javascript section.

At the moment this is not really an issue anyways because all the
other javascript parts are just functions that will (probably?) be
called from somewhere in the <body> section much later on.

If you run into any trouble with it, don't hesitate to request further
clarifications!

Thank you,

voyager-ga
koalb-ga rated this answer:5 out of 5 stars and gave an additional tip of: $5.00

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy