Click to See Complete Forum and Search --> : Question Javascript conflicts


Macman
10-06-2003, 05:24 PM
Seems that I overlooked the fact that I had a image rotator javascript on the same html page as the page that I added the marquee to. I observed the fact that the stops and starts of the marquee are exactly time to the image change. Now the question seems to be how do I make them coexist without this problem?

I discovered it by accident when I checked the same marquee on a page that didn't have the image rotator.

Now this takes me to another question. I use a pop-up at special times of the year and I remembered that I had a conflict between the pop up and image rotator script. The pop-up worked but the image rotator did not. How do I make both work?

I know I saw somewhere an answer to this that had to do with having two onload functions and how to get them both to work properly, but I can't seem to find the information in my javascript notes.

This is the pop-up script that I am using but I don't remember having the onload in the body tag it was in the head.
<html>
<head>
<!-- Start Special Announcement Pop-Up Window Code -->
<script type="text/javascript" language="JavaScript">
<!--

function run_popup() {
//
window.open('URL.com/lingerie.html', '_blank', 'width=650,height=425,scrollbars=no,status=no');
}

onload=run_popup;
//-->
</script>
<!-- End Special Announcement Pop-Up Window Code -->
</head>
<body bgcolor="#660033">

</body>
</html>

Now here is the image rotator script:
</STYLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Robert Bui (astrogate@hotmail.com) -->
<!-- Web Site: http://astrogate.virtualave.net -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
var interval=1.5; // delay between rotating images (in seconds)
var random_display = 1; // 0 = no, 1 = yes
interval *= 1800;

var image_index = 0;
image_list = new Array();
image_list[image_index++] = new imageItem("images/ban50.jpg");
image_list[image_index++] = new imageItem("images/ban245.jpg");
image_list[image_index++] = new imageItem("images/ban43.jpg");
image_list[image_index++] = new imageItem("images/ban400.jpg");
image_list[image_index++] = new imageItem("images/ban147.jpg");
var number_of_image = image_list.length;
function imageItem(image_location) {
this.image_item = new Image();
this.image_item.src = image_location;
}
function get_ImageItemLocation(imageObj) {
return(imageObj.image_item.src)
}
function generate(x, y) {
var range = y - x + 1;
return Math.floor(Math.random() * range) + x;
}
function getNextImage() {
if (random_display) {
image_index = generate(0, number_of_image-1);
}
else {
image_index = (image_index+1) % number_of_image;
}
var new_image = get_ImageItemLocation(image_list[image_index]);
return(new_image);
}
function rotateImage(place) {
var new_image = getNextImage();
document[place].src=new_image;
var recur_call = "rotateImage('"+place+"')";
setTimeout(recur_call, interval);
}
// End -->
</script>

body OnLoad="rotateImage('rImage')"

<img name="rImage" src="images/image-cycler/01.jpg" Border=0 Width="550" Height="350">

Can anyone give me a clue as to how I can make both work?
Now the last question is how do I specify in the pop-up the size of the window for Netscape since when I used this the window is to large in Netscape. I want it to be the same size in both IE and Netscape.

Macman
:confused:

Dimitri
10-06-2003, 05:42 PM
Not sure I understood what you're trying to do exactly, but I'm guessing that this is what you're trying to do:

delete the line that says:
onload=run_popup;

change the body tag to:
<body bgcolor="#660033" OnLoad="rotateImage('rImage'); run_popup()">

Lastly, to adjust the popup window props for Netscape separately from IE or other browsers, use this code:

function run_popup() {
&nbsp;&nbsp;if (navigator.appName.toUpperCase().indexOf('NETS') != -1) // runs this code if Netscape
&nbsp;&nbsp;&nbsp;&nbsp;window.open('URL.com/lingerie.html', '_blank', 'width=650,height=425,scrollbars=no,status=no');
&nbsp;&nbsp;else // otherwise, the browser runs this code
&nbsp;&nbsp;&nbsp;&nbsp;window.open('URL.com/lingerie.html', '_blank', 'width=650,height=425,scrollbars=no,status=no');
}

Adjust the props in the first window.open for NS, and the second window.open for all other browsers, until you're happy with the results in both browsers.

Hope this helped.

Dimitri

pyro
10-06-2003, 07:48 PM
Could have swore I took a stab at answering this question for you. Ah, yes, it was here (http://forums.webdeveloper.com/showthread.php?s=&threadid=18757).

Macman
10-06-2003, 10:15 PM
Sorry guys but I think I have a bigger problem. I had to move the image rotator script to a page where it would not interfere with my marquee. That leaves me with still having to get my pop-up working in IE and NS6 & 7. I also want to be able to control the size of the NS popup window much the same as I have done in IE.

Now the big problem is that I want to use this popup on either of three pages. The first is my index page which is a browser detect page which then directs either to a warning or to the agecheck page. If the page detects javascript is on & cookies are enabled it opens the agecheck page in less than 2 seconds. It is so fast that you don't even get to see the index page. From there the surfer can enter the web site on index1.

I can open a popup window in IE from my index page but nothing from NS 6 & 7. I tried your script suggestions Dimitri but still nothing even from the index page . Pyro thanks for the body placement for the functions but for some reason only the image rotator works I can still not get a popup window on that page.

Now the age check page may be a problem to stick a popup on and the reason is I have large script which is a form and cookie placement etc.

OK now here is what is on the index page which does give me the IE popup.

<html>
<head>
<title></title>
<meta name="description" content=">
<META NAME="KEYWORDS" CONTENT=">
<meta name="robots" content="index,follow">
<STYLE>
<!--
a:link { text-decoration: none }

a:active { text-decoration: none }

a:visited { text-decoration: none }

a:hover {color: #FF0000; }
//-->
</STYLE>
<script type="text/javascript" language="JavaScript">
<!--

function run_popup() {
//
window.open('http://www.the-assman.com/halloween1.html', '_blank', 'width=670,height=470,scrollbars=no,status=no');
}

onload=run_popup;
//-->
</script>
<!-- End Special Announcement Pop-Up Window Code -->

<script type="text/javascript"><!--

if(navigator.cookieEnabled){location.href="agecheck.html";

}else{location.href="warning.html";

}
//--></script>
</head>
<body text="#FFFFFF" bgcolor="#000000" link="#33FF00" alink="#33FF00" vlink="#33FF00">
<div align="center">

Now the index1 page looks just like the index page and gives me the IE popup. When I change it to the following script that Dimitri suggested

<title></title>
<meta name="description" content="">
<META NAME="KEYWORDS" CONTENT=">
<STYLE>
<!--
a:link { text-decoration: none }

a:active { text-decoration: none }

a:visited { text-decoration: none }

a:hover {color: #FF0000; }
//-->
</STYLE>
<script type="text/javascript" language="JavaScript">
<!--

function run_popup() {
__if (navigator.appName.toUpperCase().indexOf('NETS') != -1) // runs this code if Netscape
____window.open(http://www.URL.com/halloween1.html', '_blank', 'width=685,height=470,scrollbars=no,status=no');
__else // otherwise, the browser runs this code
____window.open('http://wwwURL.com/halloween1.html', '_blank', 'width=685,height=470,scrollbars=no,status=no');
}
//-->
</script>
<!-- End Special Announcement Pop-Up Window Code -->
</head>
<body OnLoad="run_popup()" bgcolor="#000000" text="#FFFFFF" link="#33FF00" alink="#33FF00" vlink="#33FF00">
<div align="center">

The result is no popup in IE or NS. Any body have some other ideas. I really would like to pop this window up in NS but I don't want a full size window if I can help it.

Thanks,

Macman
:confused:

Macman
10-07-2003, 03:36 PM
Seems that I was taking the wrong approach to my use of javasript. I solved part of the problem with some help from Pyro and a quick peek at this script this did the trick for another problem

<script>

//Popup Window Script
//By JavaScript Kit (http://javascriptkit.com)
//JavaScript tutorials and over 400+ free scripts

function openpopup(){
var popurl="thankyou.htm"
winpops=window.open(popurl,"","width=400,height=338,")
}

openpopup()

</script>

This script gives me a pop-up window in both IE and NS 6 & 7. NS 6 does not seem to be compliant with the rotate image javascript yet NS 7 does it fine.
The surprising thing is that I get the same pop-up size in both IE and NS without having to play with it. They come up exactly the same.

Still have a question however. I noticed a problem with the image rotator script that I have been using for quite some time. It seems that if I put an html marquee on the same page as I am using the image rotator , the marquee is effected each time the image is changed. It stops moving and then starts all over again. Anyone have any ideas on how to get around this?

Much thanks to all of you for the inspiration to keep plugging away at this and finally finding an answer.

Macman:)

pyro
10-07-2003, 10:31 PM
Glad you were able to get it... :)

Macman
10-08-2003, 12:00 AM
Just a thought for those that fced a problem with two function javascripts on a page. For some unknown reason the script just above that I use to for a pop-up window seems to work with another script an image rotator javascript that calls for a onload in the body tags.

Normally you would expect it not to work because you have two functions. This does not seem to have this problem. I can't explain it but I have working and it works in all the major browsers from ADL through Safari, NS 6&7 , Mozilla, and IE.

Macman:)