Welcome to WebmasterWorld Guest from 54.167.155.147

Forum Moderators: open

Message Too Old, No Replies

onload window and redirect javascript problem

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

10+ Year Member



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.

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

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



What does the WindowOpen function look like?
2:42 pm on Mar 10, 2003 (gmt 0)

10+ Year Member



<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;">

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

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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().
2:53 pm on Mar 10, 2003 (gmt 0)

10+ Year Member



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

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

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Can you post the WindowOpen() function from page1.htm.
2:58 pm on Mar 10, 2003 (gmt 0)

10+ Year Member



<SCRIPT LANGUAGE="Javascript">
var browser1 = navigator.appName;
if (browser1 == "Microsoft Internet Explorer"){
WindowOpen();
}else{
window.location.href="page2.htm";
}
</SCRIPT>
3:00 pm on Mar 10, 2003 (gmt 0)

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



<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.

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

10+ Year Member



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;">

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

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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>

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

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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.

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

10+ Year Member



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

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

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

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Drop your onload all together.
3:57 pm on Mar 10, 2003 (gmt 0)

10+ Year Member



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