homepage Welcome to WebmasterWorld Guest from 50.17.79.35
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
onload window and redirect javascript problem
deltron23




msg:1494396
 2:32 pm on Mar 10, 2003 (gmt 0)

I utilize pop up windows for my web site. I have created two pages: One for IE (page1.htm) and one for Netscape (page2.htm). The onload pop up event intiates a pop up window automatically. To redirect Netscape users to (page2.htm) I use the following code on (page1.htm)

<SCRIPT LANGUAGE="Javascript">
var browser1 = navigator.appName;
if (browser1 == "Microsoft Internet Explorer"){
WindowOpen();
}else{
window.location.href="page2.htm";
}
</SCRIPT>

This works fine; however, I am getting a javascript error when (page1.htm) loads. Here is how I have my pages organized.

1. Index.html - this page initiates the pop up window automatically -includes the onLoad="popup();">
2. page1.htm - initiates the redirect for Netscape users - includes the redirect script
3. page2.htm - Netscape users page

This might sound confusing, but I need to know why I am receiving a javascript error.

 

korkus2000




msg:1494397
 2:39 pm on Mar 10, 2003 (gmt 0)

What does the WindowOpen function look like?

deltron23




msg:1494398
 2:42 pm on Mar 10, 2003 (gmt 0)

<SCRIPT LANGUAGE="JavaScript">

<!-- HIDE
function popup() {
var newWin = window.open("page1.htm", "method_desc", "status=no,width=755,height=480")
}
//STOP HIDING -->

</SCRIPT>

</head>
<BODY onLoad="popup();return false;">

korkus2000




msg:1494399
 2:44 pm on Mar 10, 2003 (gmt 0)

Change your function popup() to function WindowOpen() and try removing the onload call to popup(). I think you need to do one or the other and call it WindowOpen() and not popup().

deltron23




msg:1494400
 2:53 pm on Mar 10, 2003 (gmt 0)

The javascript error occurs on page1.htm, not on index.html, which initiates the pop up window. Let me try to explain it a little bit more clearly.

Index.html includes the popup() event. This event initiates the pop up window (page1.htm). On (page1.htm) I have included the redirect script; this redirects Netscape users to (page2.htm)

The error occurs because of the redirect script on page1.htm. Sorry for frying your brain to try to figure out the problem. Thanks

korkus2000




msg:1494401
 2:57 pm on Mar 10, 2003 (gmt 0)

Can you post the WindowOpen() function from page1.htm.

deltron23




msg:1494402
 2:58 pm on Mar 10, 2003 (gmt 0)

<SCRIPT LANGUAGE="Javascript">
var browser1 = navigator.appName;
if (browser1 == "Microsoft Internet Explorer"){
WindowOpen();
}else{
window.location.href="page2.htm";
}
</SCRIPT>

korkus2000




msg:1494403
 3:00 pm on Mar 10, 2003 (gmt 0)

<SCRIPT LANGUAGE="Javascript">
var browser1 = navigator.appName;
if (browser1 == "Microsoft Internet Explorer"){
WindowOpen(); //What is this calling?
}else{
window.location.href="page2.htm";
}
</SCRIPT>

What is the bold piece of code calling. Do a find for WindowOpen on page1.htm and post the other piece of code you find. If you don't find anything thats your error.

deltron23




msg:1494404
 3:25 pm on Mar 10, 2003 (gmt 0)

Thanks for your input. It seems that what I want to do will not be compatible. So, if you have the time, I would like to ask another question. How could I take the code below and add an onLoad="WindowOpen() for netscape users.

Basically, what I want is for my Netscape users to be redirect to (page2.htm), automatically, as a pop up window, as well as my IE users to be redirected to (page1.htm), as a pop up window. Again, sorry if this sounds confusing.

function WindowOpen() {
var newWin = window.open("features.htm", "method_desc", "status=no,width=755,height=480")
}
//STOP HIDING -->

</SCRIPT>

</head>
<BODY onLoad="WindowOpen();return false;">

korkus2000




msg:1494405
 3:37 pm on Mar 10, 2003 (gmt 0)

Have you tried this?

<SCRIPT LANGUAGE="Javascript">
var browser1 = navigator.appName;
if (browser1 == "Microsoft Internet Explorer"){
var newWin = window.open("page1.htm", "method_desc", "status=no,width=755,height=480");
}else{
var newWin = window.open("page2.htm", "method_desc", "status=no,width=755,height=480");
}
</SCRIPT>

korkus2000




msg:1494406
 3:47 pm on Mar 10, 2003 (gmt 0)

Actually here is a better redirect script

<script>
if (is_gecko)
{
var newWin = window.open("page2.htm", "method_desc", "status=no,width=755,height=480");// JavaScript here for user agents implementing Gecko layout engine}
else if (is_nav4)
{
var newWin = window.open("page2.htm", "method_desc", "status=no,width=755,height=480"); // JavaScript here for Navigator 4
}
else if (is_ie5up)
{
var newWin = window.open("page1.htm", "method_desc", "status=no,width=755,height=480");
// JavaScript here for IE 4 and later
}
else if (is_nav3 ¦¦ is_opera)
{
// JavaScript here for Nav3 and Opera
}
else
{
// JavaScript here for Nav2 and IE 3
}
</script>

This way you can decide what you want for different versions.

deltron23




msg:1494407
 3:47 pm on Mar 10, 2003 (gmt 0)

This works, Thanks! But, I'm getting an error on the:

<BODY onLoad="WindowOpen();return false;">

korkus2000




msg:1494408
 3:50 pm on Mar 10, 2003 (gmt 0)

Drop your onload all together.

deltron23




msg:1494409
 3:57 pm on Mar 10, 2003 (gmt 0)

It worked without the error. Thank you for your expertise. You have saved me a lot of time trying to figure this out.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved