Sponsors

Tuesday, July 6, 2010

How to add a Bookmarks and SetAsHomePage link on webpage

<script>
function addfav()
{
var BookmarkURL = "http://www.learnjavaindetail.blogspot.com"
var BookmarkTitle = "Java FAQ's"
if (document.all)
{
// Add to Favorites (Internet Explorer)
window.external.AddFavorite(BookmarkURL, BookmarkTitle)
}
else
{
// Add to Bookmarks (Mozilla Firefox)
window.sidebar.addPanel(BookmarkTitle, BookmarkURL, '');
}
}

function setHomepage()
{
if (document.all)
{
document.body.style.behavior = 'url(#default#homepage)';
document.body.setHomePage('http://www.learnjavaindetail.blogspot.com');
}
else if (window.sidebar)
{
if (window.netscape)
{
try
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch(e)
{
alert("this action was aviod by your browser,if you want to enable,please enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true");
}
}
var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage', 'http://www.learnjavaindetail.blogspot.com');
}
}
</script>
<a href="javascript:addfav()">Add To Favorites</a>
<a href="javascript:setHomepage()">Set As Homepage</a>

6 comments:

  1. When i was trying to write your code it is replying a exception says "

    this action was aviod by your browser,if you want to enable,please enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true

    http://www.studentmug.com

    "

    ReplyDelete
    Replies
    1. Hello Radhakrishna,

      Indeed, you'll get this alert on Firefox. This is because, by default, for security reasons, Firefox disables the variable signed.applets.codebase_principal_support. So, if you want to allow the function setHomepage() to work on FF, you'll first have to edit the config file as said in the alert message.

      Hope this helps.

      Regards,
      Yogesh

      Delete
  2. is it possible without changing about:config file.

    ReplyDelete
  3. can we make signed.applets.codebase_principal_support = true using any script or code.i dnt want to change it by editing about:config file.so plz help me out.

    ReplyDelete
  4. setHomepage() Set As Homepage
    this line no function
    maisondemaroc maisondemaroc, [url=http://maisondemaroc.com/]maisondemaroc[/url], [link=http://maisondemaroc.com/]maisondemaroc[/link], http://maisondemaroc.com/

    ReplyDelete