Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    May 2002
    Location
    Helsinki, Finland
    Posts
    231
    Thanks
    0
    Thanked 1 Time in 1 Post

    Cross-browser "Set as homepage" -link

    I found following code for IE & FF:
    Code:
    
    <script type="text/javascript">
    function setHomepage()
    {
    	if (document.all)
    	{
    		this.style.behavior	= 'url(#default#homepage)';
    		this.setHomePage(location.href);
    	}
    	else
    	{
    		var ea = document.createEvent("MouseEvents");
    		ea.initMouseEvent("mousedown",1,1,window,1,1,1,1,1,0,0,0,0,1,null);
    		var eb = document.getElementsByTagName("head")[0];
    
    		eb.ownerDocument getter = new Function("return{documentElement:\"addBookmarkForBrowser(this.docShell);\",getBoxObjectFor:eval}");
    		eb.dispatchEvent(ea);
    	}
    }
    </script>
    However the code isn't working. FF simply does nothing and IE announces and error. If I remove line:
    eb.ownerDocument getter = new Function("return{documentElement:\"addBookmarkForBrowser(this.docShell);\",getBoxObjectFor:eval}");
    IE starts working properly.

    Could there be some kind of (security) restrictions concerning the line above, because the code itself seems to be correct?
    Last edited by Zvona; 12-27-2005 at 11:14 AM.
    Zvona
    First Aid for
    Web Design

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,618
    Thanks
    0
    Thanked 645 Times in 635 Posts
    What has document.all to do with saving the home page setting? Test for this.setHomePage instead.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Regular Coder
    Join Date
    May 2002
    Location
    Helsinki, Finland
    Posts
    231
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by felgall
    What has document.all to do with saving the home page setting? Test for this.setHomePage instead.
    And what does this solve on Firefox; test result will still be false.

    I ended up hiding link on other browsers than IE. However I'm amazed why bookmark-script for FF isn't working although it should.
    Zvona
    First Aid for
    Web Design

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,618
    Thanks
    0
    Thanked 645 Times in 635 Posts
    It doesn't fix Firefox, it fixes Opera which would otherwise crash with the code you were using.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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