Switch Between 2 Web sites On A Timer
I have 2 surveillance cameras at home that each has their own web page. If I hit each web page individually, all is good. The issue is that I want to be able to switch between them automatically without having to do anything.
Well, since I'm a Web Developer I thought why not do this myself with Javascript. The heck with calling the companies for support.
The beauty of this is that you can do this with any number of web pages you would like to switch between.
Here's how you do it.
/////////////////////////
Create the files
/////////////////////////
We will create 2 files: refreshPage1.htm and refreshPage2.htm.
Here's the code for refreshPage1.htm:
01.<script language="javascript" type="text/javascript"> 02. 04.//load indicated page every 5 seconds 05.setTimeout("loadPage();",5000);09.function loadPage() 10.{ 11. window.location.href="refreshPage2.htm"; 12.} 13.</script> 16. 17.<body> 18.You are now viewing Page 1. 19.</body> Here's the code for refreshPage2.htm:
01.<script language="javascript" type="text/javascript"> 02. 03.//load indicated page every 5 seconds 04.setTimeout("loadPage();",5000); 05. 06.function loadPage() 07.{ 08. window.location.href="refreshPage1.htm"; 09.} 10. 11.</script> 12. 13.<body> 14.You are now viewing Page 2. 15.</body>
Now put these files in the same folder and open refreshPage1.htm with any web browser.
/////////////////////////
How It Works
/////////////////////////
When you open refreshPage1.htm, the Javascript loads refreshPage2.htm. When refreshPage2.htm is opened, it loads refreshPage1.htm.
It keeps flipping back and forth forever or until you close the pages.
/////////////////////////
Considerations
/////////////////////////
A web server is not needed, just open these files with any web browser for the Javascript and HTML to execute.
Tested with IE7. Will go home tonight and test with Firefox.
This was built quickly. I imagine you can accomplish the same thing with dynamic javascript, so you only need one file.
If you'd like to load two public web sites such as Google and Yahoo, just change this line in each file:
window.location.href="http://www.google.com";
Enjoy!
Vivian
ViSO Tech


Comments