您的位置:首页 > 编程语言

设为首页 加入收藏的代码

2012-10-22 08:57 253 查看
<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://517712.com/html/zuixinyingshi/xijupian/2009/0326/143.html,则会将当前网页的域名地址(www.517712.com)设为首页。
加入到收藏夹中的实现方法为:

<a href="Javascript:window.external.addFavorite('http://www.517712.com','数字电影')">加入收藏</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.517712.com';,'数字影视基地')>加入收藏</a>
<a href=# onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('www.517712.com');">设为首页</a>

<P><a target=_top href=javascript:window.external.AddFavorite('<A href="http://www.517712.com&/" target=_blank>http://www.517712.com&</A>#39;,'<A class=Channel_KeyLink
href="http://www.517712.com/">数字影视基地</A>数字影视基地')& gt;加入收藏</a></P>
<P><BR><a href=#& amp;nbsp;onClick="this.style.behavior='url(#default#homepage)'; this.setHomePage('www.517712.com');">设为首页</a>< /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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: