PDA

View Full Version : Google Set Homepage Script



pistolpapa
05-28-2006, 09:27 AM
Here is what I wanted to achieve, exactly like google did.

1. When visitors come to the website, they see a "set it to my homepage" link
2. After user clicks on that link and confirms, the link will disappear. However, if next time when you visit the site, the homepage is altered, then the link will appear again.

There must be some kind of condition checking in the code. I tried to understand this not-so-complicated page, even set up a redirect page mgyhp.html to direct to index.html, however, no luck in successing. The link appears all the time in explorer even after setting the homepage.

<span id=hp style="behavior:url(#default#homepage)"></span>
<script>
//<!--
if (!hp.isHomePage('http://www.google.com/')) {document.write("<p><a href=\"/mgyhp.html\" onClick=\"style.behavior='url(#default#homepage)';setHomePage('http://www.google.com/');\">Make Google Your Homepage!</a>");}
//-->
</script>

pistolpapa
05-29-2006, 07:03 AM
Here is what I wanted to achieve, exactly like google did.

1. When visitors come to the website, they see a "set it to my homepage" link
2. After user clicks on that link and confirms, the link will disappear. However, if next time when you visit the site, the homepage is altered, then the link will appear again.

There must be some kind of condition checking in the code. I tried to understand this not-so-complicated page, even set up a redirect page mgyhp.html to direct to index.html, however, no luck in successing. The link appears all the time in explorer even after setting the homepage.

<span id=hp style="behavior:url(#default#homepage)"></span>
<script>
//<!--
if (!hp.isHomePage('http://www.google.com/')) {document.write("<p><a href=\"/mgyhp.html\" onClick=\"style.behavior='url(#default#homepage)';setHomePage('http://www.google.com/');\">Make Google Your Homepage!</a>");}
//-->
</script>

BUMP!

djr33
05-29-2006, 07:09 AM
Dunno.

Due to security and such, I'm pretty sure this won't work for all browsers, but might be wrong.

It seems like it would be fairly easy to google "setting homepage javascript" and get something.... maybe someone else will know.

Good luck :)


also, this is the wrong forum; should be under "javascript" or something else... this is for dynamic drive scripts.

jscheuer1
05-29-2006, 07:40 AM
<span id=hp style="behavior:url(#default#homepage)"></span>
<script>
//<!--
if (!hp.isHomePage('http://www.google.com/')) {document.write("<p><a href=\"/mgyhp.html\" onClick=\"style.behavior='url(#default#homepage)';setHomePage('http://www.google.com/');\">Make Google Your Homepage!</a>");}
//-->
</script>

For this to work, you need to change all the references to your page, not Google's. These references must all be identical (and probably include the absolute path - http://whatever) and might not work locally, only live. Finally, this is IE only code. If you view Google in other browsers, it doesn't work.

Twey
05-29-2006, 11:21 AM
Why the heck did MS decide to implement this as CSS?! It makes no sense at all!

jscheuer1
05-29-2006, 08:28 PM
To answer Twey's question -

So that it would be ignored by all (specifically earlier IE) browsers that do not support it without causing a script error. This may no longer be strictly the case in recent FF releases but, if there is an error, it would be a style error. Needless to say, this type of style probably will not validate.

I also should have added to my above post that this code probably must be on the same page that it references.

pistolpapa
05-30-2006, 11:01 AM
For this to work, you need to change all the references to your page, not Google's. These references must all be identical (and probably include the absolute path - http://whatever) and might not work locally, only live. Finally, this is IE only code. If you view Google in other browsers, it doesn't work.

Yes, I tried changing the references to my website, and I'm testing it only on IE. It does work to set the homepage, however, it doesn't disappear as the code indicates or the google webpage does, so even if I clicked on the link and set the homepage, it's still always there. Interesting huh? I've tried almost everything, but couldn't figure out what goolge did to this code and to get it work.

Twey
05-30-2006, 12:15 PM
So that it would be ignored by all (specifically earlier IE) browsers that do not support it without causing a script error.But an attribute could be used just as well.

jscheuer1
05-30-2006, 05:43 PM
Yes, I tried changing the references to my website, and I'm testing it only on IE. It does work to set the homepage, however, it doesn't disappear as the code indicates or the google webpage does, so even if I clicked on the link and set the homepage, it's still always there. Interesting huh? I've tried almost everything, but couldn't figure out what goolge did to this code and to get it work.

Have you tested it live? I think it needs to be on the server in order to know that the page set is the actual page. If you do have it live and are still having problems, give us a link to the page so we can check it out.

pistolpapa
05-31-2006, 06:15 AM
I've tested it live on the server. The code is as following, however, it doesn't work in IE, in which the "set homepage" link never disappears. And it doesn't work in firefox either, which doesn't show the link at all.

<HTML><HEAD><TITLE>Google</TITLE>
<META http-equiv=content-type content="text/html; charset=UTF-8">
<STYLE>BODY {
FONT-FAMILY: arial,sans-serif
}
TD {
FONT-FAMILY: arial,sans-serif
}
A {
FONT-FAMILY: arial,sans-serif
}
P {
FONT-FAMILY: arial,sans-serif
}
.h {
FONT-FAMILY: arial,sans-serif
}
.h {
FONT-SIZE: 20px
}
.q {
COLOR: #0000cc
}
</STYLE>

<SCRIPT>
<!--
function sf(){document.f.q.focus();}
function clk(url,oi,cad,ct,cd,sg){if(document.images){var e = window.encodeURIComponent ? encodeURIComponent : escape;var u="";var oi_param="";var cad_param="";if (url) u="&url="+e(url).replace(/\+/g,"%2B");if (oi) oi_param="&oi="+e(oi);if (cad) cad_param="&cad="+e(cad);new Image().src="/url?sa=T"+oi_param+cad_param+"&ct="+e(ct)+"&cd="+e(cd)+u+"&ei=_YZ6RPDHKoWCJZDE_JgB"+sg;}return true;}
// -->
</SCRIPT>

<META content="MSHTML 6.00.2900.2873" name=GENERATOR></HEAD>
<BODY text=#000000 vLink=#551a8b aLink=#ff0000 link=#0000cc bgColor=#ffffff
topMargin=3 onload=sf() marginheight="3">
<CENTER>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>

<TR>
<TD noWrap align=right><FONT size=-1><A
onmousedown="return clk('/url?sa=p&amp;pref=ig&amp;pval=2&amp;q=http://www.google.com/ig%3Fhl%3Den','promos','hppphou:en_us','pro','1','')"
href="http://www.google.com/url?sa=p&amp;pref=ig&amp;pval=2&amp;q=http://www.google.com/ig%3Fhl%3Den">Personalized
Home</A>&nbsp;|&nbsp;<A
href="https://www.google.com/accounts/Login?continue=http://www.google.com/&amp;hl=en">Sign
in</A></FONT></TD></TR>
<TR height=4>
<TD><IMG height=1 alt="" width=1></TD></TR></TBODY></TABLE><IMG height=110
alt=Google src="Google_files/logo.gif" width=276><BR><BR>
<FORM name=f action=/search>
<SCRIPT><!--
function qs(el) {if (window.RegExp && window.encodeURIComponent) {var ue=el.href;var qe=encodeURIComponent(document.f.q.value);if(ue.indexOf("q=")!=-1){el.href=ue.replace(new RegExp("q=[^&$]*"),"q="+qe);}else{el.href=ue+"&q="+qe;}}return 1;}
// -->
</SCRIPT>

<TABLE cellSpacing=0 cellPadding=4 border=0>
<TBODY>

<TR>
<TD noWrap><FONT size=-1><B>Web</B>&nbsp;&nbsp;&nbsp;&nbsp;<A class=q
id=1a onclick="return qs(this);"
href="http://www.google.com/imghp?hl=en&amp;tab=wi">Images</A>&nbsp;&nbsp;&nbsp;&nbsp;<A
class=q id=2a onclick="return qs(this);"
href="http://groups.google.com/grphp?hl=en&amp;tab=wg">Groups</A>&nbsp;&nbsp;&nbsp;&nbsp;<A
class=q id=4a onclick="return qs(this);"
href="http://news.google.com/nwshp?hl=en&amp;tab=wn">News</A>&nbsp;&nbsp;&nbsp;&nbsp;<A
class=q id=5a onclick="return qs(this);"
href="http://froogle.google.com/frghp?hl=en&amp;tab=wf">Froogle</A>&nbsp;&nbsp;&nbsp;&nbsp;<A
class=q id=7a onclick="return qs(this);"
href="http://www.google.com/maphp?hl=en&amp;tab=wl">Maps</A>&nbsp;&nbsp;&nbsp;&nbsp;<B><A
class=q
href="http://www.google.com/intl/en/options/">more&nbsp;</A></B></FONT></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0>
<TBODY>
<TR>

<TD width="25%">&nbsp;</TD>
<TD align=middle><INPUT type=hidden value=en name=hl><INPUT
title="Google Search" maxLength=2048 size=55 name=q><BR><INPUT type=submit value="Google Search" name=btnG><INPUT type=submit value="I'm Feeling Lucky" name=btnI></TD>
<TD vAlign=top noWrap width="25%"><FONT size=-2>&nbsp;&nbsp;<A
href="http://www.google.com/advanced_search?hl=en">Advanced
Search</A><BR>&nbsp;&nbsp;<A
href="http://www.google.com/preferences?hl=en">Preferences</A><BR>&nbsp;&nbsp;<A
href="http://www.google.com/language_tools?hl=en">Language
Tools</A></FONT></TD></TR></TBODY></TABLE></FORM><BR><BR><FONT size=-1><A
href="http://www.google.com/intl/en/ads/">Advertising&nbsp;Programs</A> - <A
href="http://www.google.com/services/">Business Solutions</A> - <A
href="http://www.google.com/intl/en/about.html">About Google</A><SPAN id=hp
style="BEHAVIOR: url(#default#homepage)"></SPAN>

<SCRIPT>
//<!--
if (!hp.isHomePage('http://www.google.com/')) {document.write("<p><a href=\"/mgyhp.html\" onClick=\"style.behavior='url(#default#homepage)';setHomePage('http://www.google.com/');\">Make Google Your Homepage!</a>");}
//-->
</SCRIPT>
</FONT>
<P><FONT size=-2>2006 Google</FONT></P></CENTER></BODY></HTML>

jscheuer1
05-31-2006, 07:40 AM
Since I posted I tried this out, this is all you need, goes in the body:


<span id=hp style="behavior:url(#default#homepage)"></span>
<script type="text/javascript">
//<!--
if (!hp.isHomePage('http://www.google.com/')) {document.write("<p><a href=\"#\" onclick=\"style.behavior='url(#default#homepage)';setHomePage('http://www.google.com/');window.location.href=window.loction.href;return false;\">Make Google Your Homepage!</a>");}
//-->
</script>

However, both instances of:

http://www.google.com/

must be changed to your domain or page and be identical to each other as well as to the domain root or (if doing a page) to the address that shows in the address bar. It must be live on the page. If you are doing a domain, it must be live in the root of the domain. As mentioned before, it is IE only. Of course, you should also change:

Make Google Your Homepage!

To text appropriate to your page or domain.

You can also do the root of a subdirectory, following all the same rules as though it were a domain. That last part I only tested on a domain name server so, it may not work if you have a directory on say freewebs or something like that.

pistolpapa
05-31-2006, 08:22 AM
I did the same thing! If you go back to the first post of this thread, you see i have the same piece of code. However, it doesn't disappear after you click on the link. And I did change the google.com part to my own domain name.

Does your link disappear after you set the page to be your homepage?

jscheuer1
05-31-2006, 08:30 AM
Yes it disappears. Post a link to your page.

And look again, the code is not identical.

pistolpapa
05-31-2006, 09:06 AM
Yes it disappears. Post a link to your page.

And look again, the code is not identical.

I was gonna say John you the man!
Then,
Dunno if I did something wrong(I copied and pasted the code into the body of my code), but it doesn't work. The botton of the screen also says "error". You think it's possible to show us your page/link?

pistolpapa
05-31-2006, 09:07 AM
When I say disappear I meant,
if the homepage is google.com already, then the page will still show, but just the link itself disappear, any kind of redirect of pages doesn't count. Just wanna clarify.

jscheuer1
05-31-2006, 09:23 AM
I made a typo in the second 'location', leaving out the 'a'. This is what caused the error which then cascades into other problems. Here is a working version of my code, the address used is the live page, the link appears in the upper left corner of the page on a dark background, so is hard to see but, it is there:


<span id=hp style="behavior:url(#default#homepage)"></span>
<script type="text/javascript">
//<!--
if (!hp.isHomePage('http://www.statestreetblues.com/2006/index2.html')) {document.write("<p><a href=\"#\" onclick=\"style.behavior='url(#default#homepage)';setHomePage('http://www.statestreetblues.com/2006/index2.html');window.location.href=window.location.href;return false;\">Make The Blues Stroll Homepage!</a>");}
//-->
</script>

Once you get the code corrected on your page, make sure to clear your cache, reload, and make sure there is no hash (#) in the address bar.

pistolpapa
05-31-2006, 09:37 PM
John you the Man!
I tried it and it worked perfectly. I'm sure this piece of code will benefit a lot of people who come here.

jscheuer1
06-01-2006, 06:46 AM
Thanks. I was playing around with this just a bit more and discovered there were errors in FF and Opera. Nothing that would 'stop the show' but annoying to any purist. Plus, this code would make any page not validate. If you put IE conditional comments around it, all that goes away and it still works fine in IE, I also added variables that allow you to configure the page or domain and text shown in just one spot (highlighted red):


<!--[if gte IE 5.5]>
<span id=hp style="behavior:url(#default#homepage)"></span>
<script type="text/javascript">
var thePage='http://www.statestreetblues.com/2006/index2.html'
var theText='Make The Blues Stroll Your Homepage!'
if (!hp.isHomePage(thePage)) {document.write("<p><a href=\"#\" onclick=\"style.behavior='url(#default#homepage)';setHomePage(thePage);window.location.href=window.location.href;return false;\">"+theText+"</a>");}

</script>
<![endif]-->

tech_support
11-13-2006, 10:24 PM
Nice ;)