• 很实用的 “设为首页”与“加入收藏”代码


    设置为首页的方法为:
    <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                   //获取网页的标题

  • 相关阅读:
    Linux系统下设置Tomcat开机自动启动
    2、nginx配置文件基本介绍
    1、Centos7下安装nginx
    40、springboot——运行状态监控使用Actuator
    39、springboot——热部署
    38、springboot——分布式之SpringCloud
    38、springboot——分布式之zookeeper+dubbo
    37、springboot——安全
    36、springboot——异步任务、定时任务、邮件任务
    React过誉了吗?
  • 原文地址:https://www.cnblogs.com/juefeiye/p/3173606.html
Copyright © 2020-2023  润新知