zoukankan      html  css  js  c++  java
  • js获取当前页面的网址域名地址

    1.获取当前完整网址
    thisURL = document.URL;
    thisHREF = document.location.href;
    thisSLoc = self.location.href;
    thisDLoc = document.location;
    strwrite = ” thisURL: [" + thisURL + "]”
    strwrite += ” thisHREF: [" + thisHREF + "]”
    strwrite += ” thisSLoc: [" + thisSLoc + "]”
    strwrite += ” thisDLoc: [" + thisDLoc + "]”
    document.write( strwrite );

    2.获取当前域名信息
    thisTLoc = top.location.href;
    thisPLoc = parent.document.location;
    thisTHost = top.location.hostname;
    thisHost = location.hostname;
    strwrite = ” thisTLoc: [" + thisTLoc + "]”
    strwrite += ” thisPLoc: [" + thisPLoc + "]”
    strwrite += ” thisTHost: [" + thisTHost + "]”
    strwrite += ” thisHost: [" + thisHost + "]”
    document.write( strwrite );

    3.获取当前页面
    tmpHPage = thisHREF.split( “/” );
    thisHPage = tmpHPage[ tmpHPage.length-1 ];
    tmpUPage = thisURL.split( “/” );
    thisUPage = tmpUPage[ tmpUPage.length-1 ];
    strwrite = ” thisHPage: [" + thisHPage + "]”
    strwrite += ” thisUPage: [" + thisUPage + "]”
    document.write( strwrite );

    location的属性介绍
    href 设置或获取整个 URL 为字符串。
    search 设置或获取 href 属性中跟在问号后面的部分。
    hash 设置或获取 href 属性中在井号“#”后面的部分。
    protocol 设置或获取 URL 的协议部分。
    host 设置或获取 location 或 URL 的 hostname 和 port 号码。
    hostname 设置或获取 location 或 URL 的 hostname
    port 设置或获取与 URL 关联的端口号码。
    pathname 设置或获取对象指定的“文件名”或路径。

    网页刷新推荐-JS
    history.go(0)
    location.reload()
    location=location
    location.assign(location)
    document.execCommand(‘Refresh’)
    window.navigate(location)
    location.replace(location)
    document.URL=location.href

  • 相关阅读:
    一个自动打补丁的脱机程序
    OPC 学习交流感想
    串口标准,说说流控制(RTS/CTS/DTR/DSR 你都明白了吗?)
    asp.net中调用COM组件发布IIS时常见错误 80070005解决方案
    可运行XP的最少后台服务配置
    MapGIS 7.0 SP2 企业版 & MapGIS 7.1IMS
    简单认识一下S60系统
    常用正则表达式
    图像处理:遮罩
    office2003中WORD中visio图无法打印中文问题解决方法
  • 原文地址:https://www.cnblogs.com/tianma3798/p/3929668.html
Copyright © 2011-2022 走看看