<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>
說明:如果當前網頁的地址為:/index.htm,則會將當前網頁的域名地址()設為首頁。
加入到收藏夾中的實現方法為:
<a href="Javascript:window.external.addFavorite(','智營網絡)">加入收藏</a>
舉壹反三,與上面設為首頁的方法壹樣,如果您要將當前網頁加入收藏,而當前網頁的網址不確定,您可以采用以下方法:
<a href="Javascript:window.external.addFavorite(document.location.href,document.title)">加入收藏</a>
其中的document.title為自動獲取當前網頁的標題的javascript代碼。
用到的代碼
document.location.host //獲取網頁域名地址
document.location.href //獲取網頁完整路徑
document.title //獲取網頁的標題