Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if then browser code works great! need platform detection as well 2

Status
Not open for further replies.

tellersix

Programmer
Oct 19, 2003
23
US
THIS CODE WORKS GREAT BUT I NEED TO EXPAND IT TO ACCOUNT FOR PLATFORM AS WELL AS BROWSER.

<SCRIPT LANGUAGE=&quot;Javascript&quot;>
if ( document.all )
window.resizeTo(369,500); // IE size
else
window.resizeTo(369,500); // others
</SCRIPT>

SOMETHING LIKE THIS EXAMPLE WRITTEN IN LAYMAN'S TERMS:

IF MACINTOSH
if ( document.all )
window.resizeTo(100,200); // IE size
else
window.resizeTo(300,400); // others

IF PC
if ( document.all )
window.resizeTo(500,600); // IE size
else
window.resizeTo(700,800); // others
 
&quot;navigator.platform&quot; is the property you want to look at...i get &quot;Win32&quot; in IE6 and Moz Firebird on Win2k Pro...don't know what Mac shows

if (navigator.platform == &quot;Win32&quot;)
// windows code
else if (navigator.platform == &quot;whateverMacIs&quot;)
// mac code



=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
WOULD IT LOOK LIKE THIS? I GUESS I'M CURIOUS: IS IT POSSIBLE TO HAVE AN &quot;IF THEN&quot; STATEMENT EMBEDED WITH IN AN &quot;IF THEN&quot; STATEMENT?

if (navigator.platform == &quot;Win32&quot;)
  //  if ( document.all )
    window.resizeTo(100,200); // IE size
else
    window.resizeTo(300,400); // others
else if (navigator.platform == &quot;whateverMacIs&quot;)
  //  if ( document.all )
    window.resizeTo(500,600); // IE size
else
    window.resizeTo(700,800); // others
 
tellersix,

Try something like this:

Code:
function browserDetect()
{
	this.agent = navigator.userAgent.toLowerCase();
//	this.majorVer = parseInt(navigator.appVersion);
//	this.minorVer = parseFloat(navigator.appVersion);
	this.ns = ((this.agent.indexOf('mozilla')!=-1) && ((this.agent.indexOf('spoofer')==-1) && (this.agent.indexOf('compatible') == -1)));
	this.ie = ((this.agent.indexOf(&quot;msie&quot;) != -1) && (this.agent.indexOf(&quot;opera&quot;) == -1));
	this.ns6 = (this.ns && (navigator.userAgent.indexOf('Netscape6') != -1));
	this.ns7 = (this.ns && (navigator.userAgent.indexOf('Netscape/7') != -1));
	this.ie55 = (this.ie && this.agent.indexOf(&quot;msie 5.5&quot;) != -1);
	this.ie5 = (this.ie && this.agent.indexOf(&quot;msie 5&quot;) != -1 && !this.ie55);
	this.safari = (navigator.userAgent.indexOf('Safari') != -1);
	this.win = (this.agent.indexOf(&quot;win&quot;)!=-1);
	this.mac = (this.agent.indexOf(&quot;mac&quot;)!=-1);
}

var browserVersion = new browserDetect()

if (browserVersion.ie && browserVersion.win) {	// ie/win }
if (browserVersion.ie5 && browserVersion.win) {	// ie5/win }
if (browserVersion.ns7 && browserVersion.win) {	// ns7/win }
if (browserVersion.ie && browserVersion.mac) {	// ie/mac }

// etc etc etc

I'm unsure as to where I picked up this code snippet, but I've modified it slightly to provide support for more browser versions.

Hope this helps!

Dan
 
i am lost, though eager to find my way. let me re phrase what my goal is here. forgive my lack of knowledge i am learning as fast as can.

i need to resize my window on load

i need the window to ask: is this user running windows or mac?

if the user is running a mac i need the window to resize to one size for explorer and a different size for navigator.

if the user is running windows i need the window to resize to one size for explorer and a different size for navigator.

four possible sizes one for win/explorer one for mac/explorer one for win/navigator and one for mac/navigator, none of the four sizes are the same.

i know there are many more browsers beyond explorer, but, in the name of my ignorance i feel it wise to start small and expand. if the code posted above does what i have just described here, i am unable to see it, and perhapse i should hit the books again, but, even if someone could verify that the code above does infact address what i have described; that would be just as helpful as telling me that it is wrong. thanks and take care.

 
tellersix
here is a very simple script that does just what your looking for i think and it doesn't do any more...it is possible to make it do more but here it is,
Code:
<script>
<!--//
if (navigator.appName==&quot;Netscape&quot; && navigator.platform==&quot;win32&quot;) {
window.resizeTo(100,200); //or whatever you need for netscape and windows
}
else if(navigator.appName==&quot;Netscape&quot; && navigator.platform!=&quot;win32&quot;) {
window.resizeTo(300,400); //or whatever you need for netscape and mac
}
else if(navigator.appName==&quot;Microsoft Internet Explorer&quot; && navigator.platform==&quot;win32&quot;) {
window.resizeTo(500,600); //or whatever you need for IE and Windows
}
else if(navigator.appName==&quot;Microsoft Internet Explorer&quot; && navigator.platform!=&quot;win32&quot;) {
window.resizeTo(800,550); //whatever you need for IE and Mac
}

//-->
</script>
Hope that helps, just to let ya know the codes above really do work it just might be hard to understand if your a beginner so you should save both and use the more complicated one for a 'learning tool'.
Jammer1221
 
whoops that doesn't work...the navigator.platform does not work...i'm looking for the correct syntax though
sorry
 
Ok heres the new code
Code:
<script>
<!--//
if (navigator.appName==&quot;Netscape&quot; && navigator.userAgent.indexOf(&quot;Win&quot;)) {
window.resizeTo(100,200); //or whatever you need for netscape and windows
}
else if(navigator.appName==&quot;Netscape&quot; && navigator.userAgent.indexOf(&quot;Mac&quot;)) {
window.resizeTo(300,400); //or whatever you need for netscape and mac
}
else if(navigator.appName==&quot;Microsoft Internet Explorer&quot; && navigator.userAgent.indexOf(&quot;Win&quot;)) {
window.resizeTo(500,600); //or whatever you need for IE and Windows
}
else if(navigator.appName==&quot;Microsoft Internet Explorer&quot; && navigator.userAgent.indexOf(&quot;Mac&quot;)) {
window.resizeTo(500,600); //or whatever you need for IE and Mac
}
//-->
</script>
what i fixed was the navigator.platform(&quot;win32&quot;) as that meant any windows 2000 and above...this new way i think will use any windows Operating Systems.
So i hope this new script helps
jammer1221
 
jammer 1221 i gave you a star because i really appreciate the effort you put into answering my question, it means a lot to me. it is because of this appreciation that it is diffucult for me to say that the code above results in the same window size when opened on a mac or windows machine (for me). perhapse it is my error, and in any case thank you very much.
 
Well did you change the size to resize to in the script...becuase i accidentally kept them the same so for either mac or windows using IE would result in a window with 500,600. If you did change that then i don't know what happened becuase i dont have a mac to test on.
sorry it didnt work out for ya
jammer1221
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top