设置为首页的方法为:
<a href=# onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('URL');event.returnValue=false;">设为首页</a>
URL就是你要设定的网址地址
要设置当前网页的地址为首页,你能够这样:
<a href=# onClick="this.style.behavior='url(#default#homepage)';this.setHomePage(document.location.href);event.returnValue=false;">设为首页</a>
上述方法采用javascript的document.location对象的href属性来得到当前网页的全路径。
同理,若是您只想将当前网页所在的域名地址设为首页,您只需将document.location.href改成document.location.host便可。示例以下:
<a href=# onClick="this.style.behavior='url(#default#homepage)';this.setHomePage(document.location.host);event.returnValue=false;">设为首页</a>
说明:若是当前网页的地址为:http://www.design007.com/design/index.htm,则会将当前网页的域名地址(www.design007.com)设为首页。
加入到收藏夹中的实现方法为:
<a href="Javascript:window.external.addFavorite('http://www.design007.com','设计007')">加入收藏</a>
触类旁通,与上面设为首页的方法同样,若是您要将当前网页加入收藏,而当前网页的网址不肯定,您能够采用如下方法:
<a href="Javascript:window.external.addFavorite(document.location.href,document.title)">加入收藏</a>
其中的document.title为自动获取当前网页的标题的javascript代码。
用到的代码
document.location.host //获取网页域名地址
document.location.href //获取网页完整路径
document.title //获取网页的标题javascript