Creating a JavaScript “Set As Homepage” Link

By  on  

The unfortunate part about creating websites for customers is that no matter what recommendation I make, if they want it, I have to give it. Thus is the case with recently adding a "Set As Homepage" link to a customer's website. Homepages are much more useful to the user when they're set to Google, Yahoo!, another portal, or they're webmail. To each their own, I guess, so here's how you create a "Set As Hompage" link using JavaScript.

The JavaScript

function set_homepage()
{
	document.body.style.behavior='url(#default#homepage)';
	document.body.setHomePage('https://davidwalsh.name');
}

I don't want to say that this link is tacky necessarily, but I think it's a bit obnoxious. If the user wanted your site to be their homepage, you wouldn't have to ask them. Also note that this only works in Internet Explorer.

Recent Features

Incredible Demos

  • By
    Create a Dynamic Table of Contents Using MooTools 1.2

    You've probably noticed that I shy away from writing really long articles. Here are a few reasons why: Most site visitors are coming from Google and just want a straight to the point, bail-me-out ASAP answer to a question. I've noticed that I have a hard time...

  • By
    CSS Sprites

    The idea of CSS sprites is pretty genius. For those of you who don't know the idea of a sprite, a sprite is basically multiple graphics compiled into one image. The advantages of using sprites are: Fewer images for the browser to download, which means...

Discussion

  1. bodohkau

    bodoh kau ni jang…

  2. reddy

    I guess this only works below IE7 ?

  3. i have put that in website, works in IE but not on FF or chrome! :(

  4. it doesn’t work on latest version of browsers

  5. Sayid Akbar

    I think . it may work in older version of all the browsers.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!