I am building a rotating page. For URLs. The problem is that the page does not reload a different URL when you refresh the page, and I want it to load a different URL when someone enters the site. I have tried different coding and nothing seems to work. Here is the code.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content=
"text/html; charset=us-ascii">
<title>Rotate Marketing</title>

<script type="text/javascript">

      <!--
 
      var Win;

      var page_index = 0;

      var page = new Array(0);
 
      page[ 0 ] = "http://www.homebiz.usaloe.com";

      page[ 1 ] = "http://www.makethatmoney.usaloe.com";

      page[ 2 ] = "";

      page[ 3 ] = "";

      page[ 4 ] = "";
     
      page[ 5 ] = "";

      page[ 6 ] = "";

      page[ 7 ] = "";

      var next_page = function() {

      page_index = (( page_index === 8 ) ? 0 : page_index );

      if ( typeof Win !== "undefined" ) {

      Win.location.href = page[ page_index ];

      } ++page_index;

      };

      

      window.onload = function() {

      Win = window.open( page[ 0 ], 'Win', 'resize=yes,toolbar=yes, status=yes,scrollbars=yes, screenX=0,screenY=0, width=1000, height=666' );

      timer = setInterval( "next_page()", 10000000 );

      };

      

      // -->

</script>
</head>
<body>
</body>
</html>

Recommended Answers

All 13 Replies

Pop up marketing is about as unfriendly as it gets, which is why most users have a pop-up blocker installed.

This is not the way to go either for you or your visitors. I think you should find a more more modern way to do it.

Airshow

Pop up marketing is about as unfriendly as it gets, which is why most users have a pop-up blocker installed.

This is not the way to go either for you or your visitors. I think you should find a more more modern way to do it.

Airshow

The pop up will be gone I have that figured out. I just cannot figure out how to get the repeat to no continue to run through the other web pages, and how to get a different website to load on page refresh. That is what I am asking for help with.

Cookie.

Can you assist me with what I need to put in the code to make it do what I want or not?

The problem is that the page does not reload a different URL when you refresh the page

that's because on every reload, the code executes again from the top, like it is the very first time it is executing. You need to "maintain" state across refreshes. For this you will need to use cookies.

Refer to the code below. Pay special attention to the HTML comment that starts with IMPORTANT...

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<title>Rotate Marketing</title>

<!-- 
IMPORTANT: Notice that I am importing "cookies.js". Go to:
http://www.quirksmode.org/js/cookies.html

scroll down to the section titled "The Scripts" and grab those three functions.
save them to a file named cookies.js and import them into your page similarly to
the way I am doing below
 -->
<script src="cookies.js" type="text/javascript"></script>

<script type="text/javascript">

      <!--
 
      var Win;

      var page_index = 0;

      var page = new Array();
      page[ page.length ] = "http://www.homebiz.usaloe.com";
      page[ page.length ] = "http://www.makethatmoney.usaloe.com";
      page[ page.length ] = "";
      page[ page.length ] = "";
      page[ page.length ] = "";
      page[ page.length ] = "";
      page[ page.length ] = "";
      page[ page.length ] = "";

      var next_page = function(){

      	//page_index = (( page_index === 8 ) ? 0 : page_index );
		page_index=++page_index % page.length;
      	if ( typeof Win !== "undefined" ) {

      		Win.location.href = page[ page_index ];
			createCookie("lastPage",page_index,30);
      	}
		

      };

      

      window.onload = function() {
	 page_index=readCookie("lastPage");
	 if(!page_index)
	 {
	 	page_index=0;
	 }
	 else
	 {
	 	page_index=++page_index % page.length;
	 }
	 createCookie("lastPage",page_index,30);
      Win = window.open( page[ page_index ], 'Win', 'resize=yes,toolbar=yes, status=yes,scrollbars=yes, screenX=0,screenY=0, width=1000, height=666' );

      timer = setInterval( "next_page()", 10000000 );

      };

      

      // -->

</script>
</head>
<body>
</body>
</html>
commented: Great bit of help. Thank you +0

please try
This (typeof Win !== undefined) instead of
( typeof Win !== "undefined")

I am not sure about it, just try.

Jino

Set some cookie first time , check the cookie and do not pop up next time.

Set some cookie first time , check the cookie and do not pop up next time.

Can you give me a example please? I tried following what the other person told me, and I am not able to get the link for some reason. Meaning that when I save the cookie as cookie.js I cannot get the JavaScript to recognize what is going on. So my screen shows blank.

On my previous post change line 53: if(!page_index) to: if(null===page_index) if you are having difficulty figuring out the path to your cookie.js file, then try typing the full path in the browser's address bar - ex:
http://www.yoursite.com/scripts/cookies.js

If you see the browser trying to download the js file OR if the browser shows you the content of cookies.js, then that IS the correct path. Once you figure out what is that full path, then use that full path as the src attribute of the script tag.

On my previous post change line 53: if(!page_index) to: if(null===page_index) if you are having difficulty figuring out the path to your cookie.js file, then try typing the full path in the browser's address bar - ex:
http://www.yoursite.com/scripts/cookies.js

If you see the browser trying to download the js file OR if the browser shows you the content of cookies.js, then that IS the correct path. Once you figure out what is that full path, then use that full path as the src attribute of the script tag.

Great that works. Now can you tell me how to keep it from being a pop up? I thought I had the coding correct but it keeps being a pop up I have tried to set the target to "_self" "_parent" "" "_blank" "_top" nothing is working

how to keep it from being a pop up?

For that, you should NOT be using window.open(). Instead, just assign the url to location.href:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<title>Rotate Marketing</title>

<!-- 
IMPORTANT: Notice that I am importing "cookies.js". Go to:
http://www.quirksmode.org/js/cookies.html

scroll down to the section titled "The Scripts" and grab those three functions.
save them to a file named cookies.js and import them into your page similarly to
the way I am doing below
 -->
<script src="cookies.js" type="text/javascript"></script>

<script type="text/javascript">

      <!--
 
      var Win;

      var page_index = 0;

      var page = new Array();
      page[ page.length ] = "http://www.homebiz.usaloe.com";
      page[ page.length ] = "http://www.makethatmoney.usaloe.com";
      page[ page.length ] = "";
      page[ page.length ] = "";
      page[ page.length ] = "";
      page[ page.length ] = "";
      page[ page.length ] = "";
      page[ page.length ] = "";

      var next_page = function(){

      	//page_index = (( page_index === 8 ) ? 0 : page_index );
		page_index=++page_index % page.length;
      	if ( typeof Win !== "undefined" ) {

      		/* Win.location.href = page[ page_index ]; */
		location.href=page[ page_index ];
		createCookie("lastPage",page_index,30);
      	}
		

      };

      

      window.onload = function() {
	 page_index=readCookie("lastPage");
	 if(!page_index)
	 {
	 	page_index=0;
	 }
	 else
	 {
	 	page_index=++page_index % page.length;
	 }
	 createCookie("lastPage",page_index,30);
      	/* Win = window.open( page[ page_index ], 'Win', 'resize=yes,toolbar=yes, status=yes,scrollbars=yes, screenX=0,screenY=0, width=1000, height=666' ); */
	location.href=page[ page_index ];

      timer = setInterval( "next_page()", 10000000 );

      };

      

      // -->

</script>
</head>
<body>
</body>
</html>

Thank you so much. I appreciate what you have taught me and helped me fix. That is GREAT.

You are welcome!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.