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
    Optimize Your Links For Print Using CSS — Show The URL

    When moving around from page to page in your trusty browser, you get the benefit of hovering over links and viewing the link's target URL in the status bar. When it comes to page printouts, however, this obviously isn't an option. Most website printouts...

  • By
    Jack Rugile’s Favorite CodePen Demos

    CodePen is an amazing source of inspiration for code and design. I am blown away every day by the demos users create. As you'll see below, I have an affinity toward things that move. It was difficult to narrow down my favorites, but here they are!

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!