Monday, June 28, 2010

Multiple Home Pages

Here is a little javascript trick [if you use NoScript, click here to skip to that section].

I have been using isc.sans.edu as my home page for some time. But today, I wanted my home page to alternate between isc.sans.edu and also infosecevents.net. So, I used a little javascript:

Open Tools / Options, paste this into "Home Page" and click OK:

javascript:var d=new Date();var h=d.getMinutes()%2;if(h==0){document.location="http://infosecevents.net"}else{document.location="http://isc.sans.edu"}

[It should paste as a single line - if not, you may have to copy/paste in pieces]

Now, click on the home page button in your toolbar and see what comes up. Then wait a minute and do it again. Cool, eh?

There are some tweaks you can make:
1. if you want the home page to change less often, you can use getHours instead of getMinutes (or go the other way with getSeconds).
2. if you want to alternate between more than two pages, try something like this (i tried a switch/case instead of the if/else, but it didn't work):

javascript:var d=new Date();var h=d.getMinutes()%4;if(h==0){document.location="http://infosecevents.net"}else if(h==1){document.location="http://isc.sans.edu"}else if (h==2){document.location="http://iamneurotic.com/"}else if (h==3){document.location="http://starnull.blogspot.com/"}

The NoScript section

Obviously, none of this is going to work if you have disallowed javascript (say, if you're using NoScript in Firefox) on the page you're on (which includes the page that opens in a new window). In that case, you can put the javascript into a local file (say, on your desktop) -- this is the equivalent of the previous example:

<xxript>
var d=new Date();
var h=d.getMinutes()%4;
if (h==0) {document.location="http://infosecevents.net"} else
if (h==1) {document.location="http://isc.sans.edu"} else
if (h==2) {document.location="http://iamneurotic.com/"} else
if (h==3) {document.location="http://starnull.blogspot.com/"}
</script>

Call it something.htm and double-click it. When Firefox opens, it will not recognize the xxript on the first line, but that is a good thing. Open Tools / Options and click "Use Current Page" under "Home Page" and click OK. Now, go back to your file and change "xxript" on the first line to "script".

Test it by starting up Firefox the way you normally do (desktop icon, quick launch icon, whatever). Ta da. The home page comes up. The only caveat here is that if you're on a page on which you have disallowed javascript and you try to hit the home page button, nothing will happen.

Have fun!

No comments:

Post a Comment