Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Google Set Homepage Script

  1. #1
    Join Date
    May 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Google Set Homepage Script

    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>

  2. #2
    Join Date
    May 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by pistolpapa
    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!

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,167
    Thanks
    44
    Thanked 3,240 Times in 3,201 Posts
    Blog Entries
    12

    Default

    Code:
    <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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Why the heck did MS decide to implement this as CSS?! It makes no sense at all!
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,167
    Thanks
    44
    Thanked 3,240 Times in 3,201 Posts
    Blog Entries
    12

    Default

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    May 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1
    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.

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,167
    Thanks
    44
    Thanked 3,240 Times in 3,201 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by pistolpapa
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    May 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •