设为首页 加入收藏的代码

来源:互联网 发布:淘宝达人时尚大咖 编辑:程序博客网 时间:2024/04/19 14:51

设为首页 加入收藏的代码

JAVASCRIPT   2009-10-23 13:22   阅读261   评论1  
字号:    
设置为首页的方法为:
<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                   //获取网页的标题



<a target=_top href=javascript:window.external.AddFavorite('http://www.ha321.com';,'MTV音乐站')>加入收藏</a>
<a href=# onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('www.ha321.com');">设为首页</a>
<P>&lt;a&nbsp;target=_top&nbsp;href=javascript:window.external.AddFavorite('<A href="http://www.mtv555.com&amp;/" target=_blank>http://www.ha321.com&amp;</A>#39;,'<A class=Channel_KeyLink href="http://www.ha321.com/">MTV音乐站</A>mtv音乐站ha321.com')&gt;加入收藏&lt;/a&gt;</P>
<P><BR>&lt;a&nbsp;href=#&nbsp;onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('www.ha321.com');"&gt;设为首页&lt;/a&gt;</P>

图片链接
<a style="cursor:hand" onclick="this.style.behavior=’url(#default#homepage)’;
this.setHomePage(’http://ha321.com/bookmark-favorites.php’);">
<img width=16 height=16 border=0 src="images/house.png">
<u> Set as Home Page</u></a>

1.文字型:
<a onclick="this.style.behavior=’url(#default#homepage)’;this.setHomePage(’http://www.ha321.com’);" href="#">設為首頁</a>
範例:
設為首頁
2.按鈕型:
<input TYPE="button" VALUE=" 設為首頁 " onclick="this.style.behavior=’url(#default#homepage)’;this.setHomePage(’http://www.ha321.com’);" href="#">
离开时自动提示设为首页
<body onunload="BASEBody.style.behavior=’url(#default#homepage)’;if(!(BASEBody.isHomePage(’http://ha321.com')))BASEBody.setHomePage(’http://www.ha321.com/’);">
-------------------------------------------------------------
打开页面时自动弹出窗口询问是否设为首页 字串7
将以下代码放在<head></head>之间:
<script language="javascript">
function myhomepage(){
this.homepage.style.behavior=’url(#default#homepage)’;this.homepage.sethomepage(’http://www.ha321.com’);
}
</script>
<p align="center"><a href="http:ha321.com" name="homepage"
onclick="myhomepage();"></a>


再将下面代码加入<body>内:
onload="myhomepage();"
即:<body onload="myhomepage();">
------------------------------------------------------------------------------
鼠标指向时提示设为首页
将下列代码插入<body>区中:
<A href="http://www.netbei.com/" onmouseover="this.style.behavior=’url(#default#homepage)’;this.setHomePage(’http://www.ha321.com’);" target="_blank">设为首页</A>
-------------------------------------------------------------------------------
关闭当前窗口的功能
  这里我们可以先输入用来标示的文字“关闭窗口”,用鼠标拖动选中它,在“Link”输入框中键入“/”,同时切入源代码窗口,在链接代码中键入该事件-onclick=“javascript:window.close(); return false;”。

字串2


  完整的代码为:< a href=“/”onclick=“javascript:window.close(); return false;”>关闭窗口< /a>