當前位置:吉日网官网 - 錢幣收藏 - 怎麽在主頁中設置“加入收藏”和“設為首頁”

怎麽在主頁中設置“加入收藏”和“設為首頁”

設置為首頁的方法為:

<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 //獲取網頁的標題

  • 上一篇:必聽的20首經典英文歌是什麽?
  • 下一篇:qq如何刪除歷史頭像?
  • copyright 2024吉日网官网