-- online Search!

Set Home Page Link

by kirupa   | filed under Web, HTML, CSS, and XML

TL;DR

A Set Home Page link prompts visitors with the option of making your page their home page. The trick is a small setHome() JavaScript function that sets document.body.style.behavior to the homepage behavior and calls setHomePage(), which you trigger from an ordinary hyperlink using the javascript: identifier.

  • If you know how to create a hyperlink to another page, you can create a Set Homepage link; just point it at javascript:setHome().
  • window.location.href gets the full URL of the current page. Swap it for a quoted URL like http://www.kirupa.com to set a specific home page.
  • Remember to copy the whole function, the chunk of code beginning with function setHome(), into your page.

This is an archived tutorial from the kirupa.com legacy collection. It covers software that may no longer be available, but it is kept online because the ideas still hold up.

What would be cooler than having someone set your site as their home page? Before you gaze starry eyed toward the future, let's hope you know how to create a home page link. A homepage link is a link, when clicked, that prompts the visitor with the option of setting your page as their home page.

For an example of what I am referring to, click the following button:

Poll

 Set as Home Page

The Code

The simplest way of implementing the JavaScript code would be to include it in a hyperlink. Copy and paste the following code into Notepad or your HTML editor and preview the page in your browser:

  <html>

<head>
<title>kirupa.com</title>

<script language="JavaScript">
function setHome()
{
  document.body.style.behavior='url(#default#homepage)';
  document.body.setHomePage(window.location.href);
}
</script>

</head>

<body>

<a href="javascript:setHome()">
Set Home Page</a>

</body>

</html>

Basically, if you know how to create a hyperlink to a different page, you will be able to create a Set Homepage link. There is one characteristic that you should take note of:

  • window.location.href

    This parameter gets the full URL of the current page. If you want to set the home page of a specific URL, change window.location.href to the actual URL such as "http://www.kirupa.com" - with the quotation marks:

document.body.setHomePage("http://www.kirupa.com");

Just remember to copy the function - the chunk of code beginning with function setHome(), and do not forget to hyperlink to your function setHome() with the javascript: identifier before it.

I hope the information helped. If you have any questions or comments, please don't hesitate to post them on the kirupa.com Forums. Just post your question and I, or our friendly forum helpers, will help answer it.

The following is a list of related tutorial and help resources that you may find useful:

How to use the Forums
New, Upcoming, and In-Progress Tutorials
How to Help out kirupa.com
Writing Tutorials
Cheers!
Kirupa Chinnathambi
kirupaBlog

Before you go, here are a few things you can do:

  1. Ask a question

    Stuck on something, or curious about a detail we skipped? Ask on the forums, and we’ll help you out.

Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence slop, ads, and algorithm-driven doodads. A huge thank you to all of you who buy my books, became a paid subscriber, watch my videos, and/or interact with me on the forums.

Your support keeps this site going! 😇

Kirupa's signature!

The KIRUPA Newsletter

Thought provoking content that lives at the intersection of design 🎨, development 🤖, and business 💰 - delivered weekly to over a bazillion subscribers!

SUBSCRIBE NOW

Creating engaging and entertaining content for designers and developers since 1998.

Follow:

Popular

Loose Ends

:: Copyright © KIRUPA 2026 //--