PDA

View Full Version : Code for making website home page



dophinsluv
06-16-2007, 08:37 PM
Questions:

The following code came from http://google.com and allows the user to make your site a home page. If the page is already the user's home page the link doesn't appear.



<span id=hp style="behavior:url(#default#homepage)"></span><script><!--
(function() {var a="http://yourwebsite.com/",b=document.getElementById("hp"),c=b.isHomePage(a);_rptHp=function(){(new Image).src="/gen_204?sa=X&ct=mgyhp&cd="+(b.isHomepage(a)?1:0)};if(!c){document.write('<p><a href=/mgyhp.html onClick=document.getElementById("hp").setHomepage("'+a+'");_rptHp();>Make TheWebTitan Your Homepage!</a>')};})();//-->
</script>


Here are the questions:
Can someone explain what the code is doing?
Google doesn't specify a default client script language. How do they know what script language the browser will run?
What is "/gen_204..." doing? Robots don't seem to like this very much. They can't find the link.

Thanks for your help!

felgall
06-17-2007, 01:28 AM
It is using JScript inside of CSS to control the span tag and the JScript that follows tests if the current page is the one set as the Internet Explorer home page and if it isn't adds the code to ask if the person wants to make it their home page.

It relies on proprietary functionality built into JScript (which only runs in Internet Explorer) and also other proprietary IE functionality to operate and so will only ever work in that browser. Other browsers will just ignore the code as it is invalid when processed as CSS and JavaScript.

Presumably it will display the link but be non-functional in IE where the person has sensibly locked their home page to prevent browser hijacking.

Browsers other than IE do not allow the home page to be set from within web pages. The home page is not something that people change very often and the facility built into their browser to set the current page as the home page is quite adequate for doing so. The ability of JScript code running in IE to update the home page is what makes browser hijacking possible in the first place. Those web pages change the home page without asking and then lock it so that unless the person knows how to unlock it they can't easily change it back.