`

jquery/js获取当前页面url地址程序代码

 
阅读更多

转自:http://www.111cn.net/wy/js-ajax/52767.htm

本文章来给各位同学介绍关于jquery/js获取当前页面url地址程序代码,在jquery与js中获取当前页面url方法是一样的,因为jquery没有自己相关的函数哦,都是使用js windows方法来获取。

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

设置或获取对象指定的文件名或路径。

代码如下 复制代码
<script>
alert(window.location.pathname)
</script>

设置或获取整个 URL 为字符串。

代码如下 复制代码

<script>

alert(window.location.href);
</script>

设置或获取与 URL 关联的端口号码。

代码如下 复制代码
<script>
alert(window.location.port)
</script>

设置或获取 URL 的协议部分。

代码如下 复制代码
<script>
alert(window.location.protocol)
</script>

设置或获取 href 属性中在井号“#”后面的分段。

代码如下 复制代码
<script>
alert(window.location.hash)
</script>

设置或获取 location 或 URL 的 hostname 和 port 号码。

代码如下 复制代码
<script>
alert(window.location.host)
</script>

设置或获取 href 属性中跟在问号后面的部分。

代码如下 复制代码
<script>
alert(window.location.search)
</script>


如果获取“当前”域名

host = window.location.host;

url=document.domain;

url = window.location.href;

取得完整url路径: 用以下代码可以完整研证结果:

<table width=100% cellpadding=0 cellspacing=0 border=0 >
<script>
thisURL = document.URL;
thisHREF = document.location.href;
thisSLoc = self.location.href;
thisDLoc = document.location;
strwrite = "<tr><td valign=top>thisURL: </td><td>[" + thisURL + "]</td></tr>"
strwrite += "<tr><td valign=top>thisHREF: </td><td>[" + thisHREF + "]</td></tr>"
strwrite += "<tr><td valign=top>thisSLoc: </td><td>[" + thisSLoc + "]</td></tr>"
strwrite += "<tr><td valign=top>thisDLoc: </td><td>[" + thisDLoc + "]</td></tr>"
document.write( strwrite );
</script>
thisDLoc = document.location; <BR>
thisURL = document.URL; <BR>
thisHREF = document.location.href; <BR>
thisSLoc = self.location.href;<BR>
<script>
thisTLoc = top.location.href;
thisPLoc = parent.document.location;
thisTHost = top.location.hostname;
thisHost = location.hostname;
strwrite = "<tr><td valign=top>thisTLoc: </td><td>[" + thisTLoc + "]</td></tr>"
strwrite += "<tr><td valign=top>thisPLoc: </td><td>[" + thisPLoc + "]</td></tr>"
strwrite += "<tr><td valign=top>thisTHost: </td><td>[" + thisTHost + "]</td></tr>"
strwrite += "<tr><td valign=top>thisHost: </td><td>[" + thisHost + "]</td></tr>"
document.write( strwrite );
</script>
thisTLoc = top.location.href; <BR>
thisPLoc = parent.document.location; <BR>
thisTHost = top.location.hostname; <BR>
thisHost = location.hostname;<BR>
<script>
tmpHPage = thisHREF.split( "/" );
thisHPage = tmpHPage[ tmpHPage.length-1 ];
tmpUPage = thisURL.split( "/" );
thisUPage = tmpUPage[ tmpUPage.length-1 ];
strwrite = "<tr><td valign=top>thisHPage: </td><td>[" + thisHPage + "]</td></tr>"
strwrite += "<tr><td valign=top>thisUPage: </td><td>[" + thisUPage + "]</td></tr>"
document.write( strwrite );
</script></table>
 
运行如下: thisDLoc = document.location;
thisURL = document.URL;
thisHREF = document.location.href;
thisSLoc = self.location.href;
thisTLoc = top.location.href;
thisPLoc = parent.document.location;
thisTHost = top.location.hostname;
thisHost = location.hostname;
thisURL:  [http://weibo.com/js/jsweibourl.html]
thisHREF:  [http://weibo.com/js/jsweibourl.html]
thisSLoc:  [http://weibo.com/js/jsweibourl.html]
thisDLoc:  [http://weibo.com/js/jsweibourl.html]
thisTLoc:  [http://weibo.com/js/jsweibourl.html]
thisPLoc:  [http://weibo.com/js/jsweibourl.html]
thisTHost:  [weibo.com]
thisHost:  [weibo.com]
thisHPage:  [jsweibourl.html]
thisUPage:  [jsweibourl.html]

window.location

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

分享到:
评论

相关推荐

    jQuery权威指南-源代码

    1.1.5 jQuery程序的代码风格/5 1.2 jQuery的简单应用/7 1.2.1 jQuery访问DOM对象/7 1.2.2 jQuery控制DOM对象/7 1.2.3 jQuery控制页面CSS /9 1.3 本章小结/11 第2章 jQuery 选择器/12 2.1 jQuery选择器概述/...

    js框架jquery实现幸运大转盘抽奖程序代码,兼容多种浏览器.zip

    &lt;script type="text/javascript" src="jquery.easing.min.js"&gt;&lt;/script&gt; 08 &lt;script type="text/javascript" src="zp.js"&gt;&lt;/script&gt; 09 &lt;style type="text/css"&gt; 10 body { 11 background: url(bg.png) 0 0 repeat;...

    超实用的jQuery代码段

    超实用的jQuery代码段精选近350个jQuery代码段,涵盖页面开发中绝大多数要点、技巧与方法,堪称史上最实用的jQuery代码参考书,可以视为网页设计与网站建设人员的好帮手。《超实用的jQuery代码段》的代码跨平台、跨...

    jQuery详细教程

    如果您的网站包含许多页面,并且您希望您的 jQuery 函数易于维护,那么请把您的 jQuery 函数放到独立的 .js 文件中。 当我们在教程中演示 jQuery 时,会将函数直接添加到 &lt;head&gt; 部分中。不过,把它们放到一个单独的...

    jquery插件使用方法大全

     代码 $("selector").load(url,data,function(response,status,xhr)) 该方法是最简单的从服务器获取数据的方法。它几乎与 $.get(url, data, success) 等价,不同的是它不是全局函数,并且它拥有隐式的回调函数。当...

    jquery ui 后台界面演示系统 登陆界面

    jQuery UI标准后台页面演示系统说明 系统的设计目的 我做B/S软件开发,基本上还是采用原型法的--嗯,好吧,可能原型法还是往自己脸上贴金了。俗一点说吧,就是和客户定一个尽可能详细的功能描述文档,然后按文档写完...

    jQuery权威指南366页完整版pdf和源码打包

    jquery开发入门/1 1.1 jquery概述/2 1.1.1 认识jquery /2 1.1.2 jquery基本功能/2 1.1.3 搭建jquery开发环境/3 1.1.4 编写第一个简单的jquery应用/3 1.1.5 jquery程序的代码风格/5 1.2 jquery的简单...

    Jquery遮罩ShowLoading组件

    二、JQuery遮罩UI实现 &lt;link href="style/showLoading.css" rel="stylesheet" type="text/css" /&gt; &lt;script type="text/javascript" src="js/jquery.showLoading.min.js"&gt;&lt;/script&gt; 三、使用方法 假设html页面有有一...

    jQuery.validate.js文件+使用文档+具体代码案例

    jQuery Validate 插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求。该插件捆绑了一套有用的验证方法,包括 URL 和电子邮件验证,同时提供了一个用来...

    jquery ui 后台界面演示系统 v0.1.rar

    jQuery UI标准后台页面演示系统说明 系统的设计目的 我做B/S软件开发,基本上还是采用原型法的--嗯,好吧,可能原型法还是往自己脸上贴金了。俗一点说吧,就是和客户定一个尽可能详细的功能描述文档,然后按文档写...

    JavaScript基础教程第8版

    《JavaScript基础教程(第8版)》循序渐进地讲述了JavaScript及相关的CSS、DOM、Ajax、jQuery等技术。书中从JavaScript语言基础开始,分别讨论了图像、框架、浏览器窗口、表单、正则表达式、用户事件和cookie,并在上...

    fake-ajax-server:用于集成 JavaScript 测试规范的 jQuery 请求的假 Ajax 服务器

    用 Sinon.js 伪造你的 AJAX jQuery 请求,并在你的测试/规范中存根响应。 安装 将此行添加到应用程序的 Gemfile 中: gem 'fake-ajax-server', group: [:development, :test] 然后执行: $ bundle 也可以在 ...

    大名鼎鼎SWFUpload- Flash+JS 上传

     SWFUpload不同于其他基于Flash构建的上传工具,它有着优雅的代码设计,开发者可以利用XHTML、CSS和JavaScript来随心所欲的定制它在浏览器下的外观;它还提供了一组简明的JavaScript事件,借助它们开发者可以方便的...

    jquery.appendGrid:动态表输入JavaScript插件

    为了保留GitHub项目URL,以便未更改存储库名称。 通过使用ES6重写新代码。 它将与现代Web框架兼容,例如和 。 对于基于 ,将仅提供错误修复。先决条件不,只需要一个可以运行JavaScript的现代网络浏览器即可!演示...

    HMIS-App:DHIS2应用程序,用于将数据输入到DHIS2的另一个实例中

    DHIS2仪表板应用程序嵌入静态远程URL 此应用程序最初旨在在基于DHIS2的国家健康管理信息系统(HMIS)中显示预警报告系统(EWARS)的静态仪表板。 代码 index.html &lt; html lang =" en " &gt; &lt; head &gt; &...

    CSS and Javascript Injection-crx插件

    语言:English 此插件将记住您在每个网站上注入的所有CSS / JS代码,并在加载网页时自动注入它们 您可以使用此插件将CSS / JavaScript代码...现在,您可以在没有jQuery的页面中注入jQuery代码(JQuery-2.1.4)版本1.0.

    jQuery响应式宽屏图片3D旋转切换特效.zip

    Netscape公司 Navigator 3.0以上版本的浏览器都能支持 Javascript程序,微软公司Internet Explorer 3.0以上版本的浏览器基本上支持Javascript。微软公司还有自己开发的Javascript,称为JScript。 Javascript和...

    最新Python3.5零基础+高级+完整项目(28周全)培训视频学习资料

    javascript代码存在形式 javascript基本预览 javascript字符串操作以及跑马灯实例 javascript数组和字典以及for循环 javascript条件语句 javascript函数的定义 Dom直接选择器 Dom间接选择器 示例之模态对话框 示例之...

    JQuery实现ajax上传文件示例源码20121029

    JQuery实现ajax上传文件示例源码 源码描述: url用来指定后台处理的程序,fileElementId指的是文件选择框的ID,dataType用来指定返回的数据格式,支持xml、script、json和html。 返回的json的格式最简单:{error:'...

    ScriptSnap-crx插件

    语言:English 通过将任何JavaScript代码的执行分配给击键来减少花在普通任务上的...书签:简单(仅静态URL),智能(取决于当前URL和/或页面内容的URL),参数化(具有从用户输入中获取的参数值的URL),混合参数(使用

Global site tag (gtag.js) - Google Analytics