首页 » 操作技巧及代码 » 设为首页及加入收藏代码

设为首页及加入收藏代码


Warning: array_keys() [function.array-keys]: The first argument should be an array in D:\wwwroot\szblog\wp-content\plugins\simple-tags\inc\client.php on line 1310

Warning: shuffle() expects parameter 1 to be array, null given in D:\wwwroot\szblog\wp-content\plugins\simple-tags\inc\client.php on line 1311

Warning: Invalid argument supplied for foreach() in D:\wwwroot\szblog\wp-content\plugins\simple-tags\inc\client.php on line 1312

设置为首页的方法为:
<a href=# onClick=”this.style.behavior=’url(#default#homepage)’;this.setHomePage(‘www.szglobal.net’);event.returnValue=false;”>设为首页</a>
www.szglobal.net换成你要设定的网址地址

要设置当前网页的地址为首页,你可以这样:
<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.szglobal.net/hosting.asp ,则会将当前网页的域名地址(www.szglobal.net)设为首页。

加入到收藏夹中的实现方法为:
<a href=”Javascript:window.external.addFavorite(‘http://www.szglobal.net‘,’深圳虚拟主机’)”>加入收藏</a>

举一反三,与上面设为首页的方法一样,如果您要将当前网页加入收藏,而当前网页的网址不确定,您可以采用以下方法:
<a href=”Javascript:window.external.addFavorite(document.location.href,document.title)”>加入收藏</a>
其中的document.title为自动获取当前网页的标题的javascript代码。

用到的代码
document.location.host      //获取网页域名地址
document.location.href      //获取网页完整路径
document.title                   //获取网页的标题

以上代码注意把全角称号改为半角的

Related posts:

  1. 用js自定义滚动条样式
  2. 六种Javascript网页打印方法
  3. 世界50大最美景色惊艳图集三
  4. 世界50大最美景色惊艳图集一
  5. 股市赚大钱的八要则
  6. 用Javascript打印指定部分内容的五种方法
  7. 智能建站虚拟主机引领建站热潮
  8. 利用百度快照优化自己的网站的几种方式
  9. 怎样使用电子邮件客户端程序(如 Outlook)来发送和阅读邮件?

转发到新浪微博 转发到新浪微博


目前这篇文章还没有评论(Rss)

我要评论