js获取当前地址 JS获取当前URL的示例代码

代码如下:

<table width=100% cellpadding=0 cellspacing=0 border=0 >
<script language="javascript">
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 language="javascript">
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 language="javascript">
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><tr><td>

(0)

相关推荐

  • javascript/jquery获取地址栏url参数的方法

    使用jquery获取url以及使用jquery获取url参数是我们经常要用到的操作 1.jquery获取url很简单,代码如下 复制代码 代码如下: window.location.href; 其实只是用到了javascript的基础的window对象,并没有用jquery的知识 2.jquery获取url参数比较复杂,要用到正则表达式,所以学好javascript正则式多么重要的事情 首先看看单纯的通过javascript是如何来获取url中的某个参数 复制代码 代码如下: function

  • js和php如何获取当前url的内容

    #测试网址: http://localhost/blog/testurl.php?id=5 复制代码 代码如下: //获取域名或主机地址 echo $_SERVER['HTTP_HOST']."<br>"; #localhost //获取网页地址 echo $_SERVER['PHP_SELF']."<br>"; #/blog/testurl.php //获取网址参数 echo $_SERVER["QUERY_STRING"

  • JS实现获取当前URL和来源URL的方法

    本文实例讲述了JS实现获取当前URL和来源URL的方法.分享给大家供大家参考,具体如下: index.html: <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1,max

  • nodejs实现获取当前url地址及url各种参数值

    复制代码 代码如下: //需要使用的模块 http   url 当前url   http://localhost:8888/select?aa=001&bb=002 var http = require('http'); var URL = require('url'); http.createServer(function(req, res){    var arg = url.parse(req.url).query;  //方法一arg => aa=001&bb=002   

  • 解析js如何获取当前url中的参数值并复制给input

    复制代码 代码如下: function getObject(objectId) {    if (document.getElementById && document.getElementById(objectId)) {        return document.getElementById(objectId);    } else if (document.all && document.all(objectId)) {        return documen

  • js获取url参数值的两种方式

    方法一:正则分析法 复制代码 代码如下: function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return n

  • url 编码 js url传参中文乱码解决方案

    1.配置文件web.config中 在节中加上整个网站的编码方式. <globalization fileEncoding="GB2312" requestEncoding="GB2312" responseEncoding="GB2312"/> 这样参数就以gb2312的中文编码方式传输了.而一般默认是utf-8. 2.在传参是先编码在传输,接受时先编码,在接收. string mm=Server.URLEncode(你); Res

  • JS 中document.URL 和 windows.location.href 的区别

    document 表示的是一个文档对象,windows 表示一个窗口对象. 一个窗口下面可以有很多的document对象.每个document 都有 一个URL. 但是,这不是所有的区别.当你ctrl + F5 一个链接 http://www.jb51.net/#server 打印 alert(document.URL ); 和 alert(windows.location.href); 发现,这两个的值不一样, document.URL : http://www.jb51.net/ windo

  • JS URL传中文参数引发的乱码问题

    解决方法如下: 1.在JS里对中文参数进行两次转码 复制代码 代码如下: var login_name = document.getElementById("loginname").value; login_name = encodeURI(login_name); login_name = encodeURI(login_name); 2.在服务器端对参数进行解码 复制代码 代码如下: String loginName = ParamUtil.getString(request, &

  • 在jsp页面如何获得url参数

    当一个url过来时,如:http://localhost:8080/pro/demo/hello.jsp?name=john,在hello.jsp页面,我们可以这样得到name的值: 复制代码 代码如下: <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getSer

  • JavaScript获取当前url根目录(路径)

    主要用到Location 对象,包含有关当前 URL 的信息,是 Window 对象的一个部分,可通过 window.location 属性来访问. 方法一 (window.document.location.href/window.document.location.pathname) ------------转自网络 function getRootPath_web() { //获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp

随机推荐