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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

load a page in open window depending on browser version 1

Status
Not open for further replies.

hablablow

Programmer
Sep 9, 2000
115
FR
On a page several links are mixed with an open window.
As the new windows opens, i would like to display in it the proper page for Msie and Netscape.
The document displayed in the new window contains layers.
There are two types of document: 1 for Ie and 1 for Ns4
On a previous thread MatthewP, programmer, suggested this:

ns4=(document.layers)? true:false
ns6 =(document.getElementById && !document.all)? true:false
ie=(document.all)? true:false

if (ns4){location="netscape.html"}
if (ie){location="msie.html"}

To open my window i use this script:

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
var exwin=null;
function MM_openBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
if(window.screen)if(isCenter)if(isCenter==&quot;true&quot;){
var myLeft = (screen.width-myWidth)/2;
var myTop = (screen.height-myHeight)/2;
features+=(features!='')?',':'';
features+=',left='+myLeft+',top='+myTop;
}
if(exwin!=null)exwin.close();
window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}


//-->
</SCRIPT>

How can i add code to include a browser dependent display page in my open window event ?

Thanks alot for your help and incomming posts.
Hablablow.
 
How about something like this.
Code:
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
ns4=(document.layers)? true:false
ns6 =(document.getElementById && !document.all)? true:false
ie=(document.all)? true:false

var exwin=null;
function MM_openBrWindow(winName,features, myWidth, myHeight, isCenter) { //v3.0

  if (ns4){theURL=&quot;netscape.html&quot;}
  if (ie){theURL=&quot;msie.html&quot;}


  if(window.screen)if(isCenter)if(isCenter==&quot;true&quot;){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  if(exwin!=null)exwin.close();
  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}
//-->
</SCRIPT>

Now, I tweaked with Matthew's window.open() method a little which removed the passed parameter for the theURL variable. So that means that this function is not re-usable for any other links on the page. It will only navigate to one of the two pages provided. If you wanted to make this re-usable for other links on the page, you're going to have to do some document.write() methods in your HTML where you specify the link to be clicked to open the new window.

If you want that, or conversly, a more simplified approach to the window.open() method without window parameters, just let myself or Matthew know by posting that back here.

ToddWW
 
Thank you ToddWW for your answer.
I have choosen to handle the problem for the child window: a dreamweawer script to detect browser and display appropriate url.
I understand your script but it will handle only 1 link on parent and i have 3.
Thank you for your help.
Hablablow
 
ToddWW

OK, if you want to use Matthew's opener script, you're going to have to pass the URL in the link along with a bunch of other information. But it's a nice script so here's how you can do it.

Code:
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
ns4=(document.layers)? true:false
ns6 =(document.getElementById && !document.all)? true:false
ie=(document.all)? true:false

var exwin=null;
function MM_openBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
  if(window.screen)if(isCenter)if(isCenter==&quot;true&quot;){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  if(exwin!=null)exwin.close();
  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}

Then in your HTML something like this.
Code:
<a href=&quot;javascript:MM_openBrWindow(
<script Language=&quot;JavaScript&quot;>
<!--
if (ns4){document.write(&quot;'netscape.html'&quot;)}
if (ie){document.write(&quot;'msie.html'&quot;)}
//-->
</script>
,'win0','',300,200,true);&quot;>New Window Link</a>

I know that looks sort of confusing and it's just one way to accomplish what you want. But if you look closely, you'll see that JavaScript is writing the web page URL into that function's parameter list based on browser detection. This way, the opener function can be reused for other links in your document. All you have to modify is the way the links are written like I have above.

Is this making sense ??

ToddWW





 
Todd's suggestion is good, but I have a suggestion that might make it even easier: store your web pages in two different subdirectories, one for IE and one for NS, then use the SAME PAGE NAME for both versions and store them in the appropriate subdirectories.

For the links all you would have to do is pass the page name. The opener function would then determine which browser the user has and prepend the appropriate subdirectory. That way it would work for virtually ANY page without modification.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Thanks alot for both of you but i handled it finally with a browser detect script in the child that displays the proper page for each browser.
Todww i understand clearly your script but it is a little tricky and will become heavy
because i have 9 links targeting to child....means 9 times repeating the script in my body.....Anyway i am glad we discussded about this subject.
About Netscape 6, Matt told me it handled layers much more like Ie, different from netscape4+....and that few people used it because of several bugs....
What about this browser ? Is it really necessary to had a script for them ?

Thanks alot for your help and incomming posts.
Hablablow.
 
Tracy Dragon.. Much more efficient.

Why am I always doing things the hard way ?? :)

ToddWW
 
Toddww your message is surprising ?
The Tracys script seems so simple that i don't understand it !!
I understand yours but when it is simple i am lost like you do.
Does Tracy mean that when you use a simple open window method the browser is able to determine in wich named folder, ie or ns, to open the document ?

Hablablow.
 
No, the browser isn't able to determine that, but your open function can. Then all it has to do is take the page name you passed to it, prepend the correct folder name, and use that. I didn't actually GIVE a &quot;script&quot;, just an IDEA how to make a simple script. That's probably why it seems so simple. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Using Tracy's great idea, something like this should work.
Code:
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
ns4=(document.layers)? true:false
ns6 =(document.getElementById && !document.all)? true:false
ie=(document.all)? true:false

var exwin=null;
function MM_openBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
  if(window.screen)if(isCenter)if(isCenter==&quot;true&quot;){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  if(exwin!=null)exwin.close();

  var myFolder
  if (ns4){myFolder = &quot;nsfolder&quot;}
  if (ie){myFolder = &quot;iefolder&quot;}

  theURL = myFolder + &quot;/&quot; + theURL

  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}
//-->
</SCRIPT>


Then in your HTML something like this.

<a href=&quot;javascript:MM_openBrWindow('somepage.htm','win0','',300,200,true);&quot;>New Window Link</a>

Then store the pages in different folders but with the same file names.

ToddWW
 
Good job Todd! I was too lazy today to actually WRITE a script to do what I was suggesting. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
THANK YOU VERY MUCH for both of you...
Tracy you had an idea....
ToddWW you did it all.
By the way i started another thread for this and had no answer:
Do you know if you can reload IMAGES ONLY in parent window when you close the child ?

Hablablow
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top