...

View Full Version : Cross-browser "Set as homepage" -link



Zvona
12-27-2005, 10:24 AM
I found following code for IE & FF:


<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?

felgall
12-27-2005, 08:52 PM
What has document.all to do with saving the home page setting? Test for this.setHomePage instead.

Zvona
12-28-2005, 08:31 AM
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.

felgall
12-28-2005, 10:26 PM
It doesn't fix Firefox, it fixes Opera which would otherwise crash with the code you were using.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum