
实现方法:
一:获取URL带QUESTRING参数的JAVASCRIPT客户端解决方案,相当于asp的requestquerystring,PHP的$_GET
1函数:
<Script language="javascript">
function GetRequest() {
var url = locationsearch; //获取url中""符后的字串
var theRequest = new Object();
if (urlindexOf("") != -1) {
var str = urlsubstr(1);
strs = strsplit("&");
for(var i = 0; i < strslength; i ++) {
theRequest[strs[i]split("=")[0]]=(strs[i]split("=")[1]);
}
}
return theRequest;
}
</Script>
2然后通过调用此函数获取对应参数值:
<Script language="javascript">
var Request = new Object();
Request = GetRequest();
var 参数1,参数2,参数3,参数N;
参数1 = Request[''参数1''];
参数2 = Request[''参数2''];
参数3 = Request[''参数3''];
参数N = Request[''参数N''];
</Script>
以此获取url串中所带的同名参数
二、正则分析法。
function GetQueryString(name) {
var reg = new
RegExp("(^|&)" + name +
"=([^&])(&|$)","i");
var r =
windowlocationsearchsubstr(1)match(reg);
if (r!=null) return
(r[2]); return null;
}
alert(GetQueryString("参数名1"));
alert(GetQueryString("参数名2"));
alert(GetQueryString("参数名3"));
其他参数获取介绍:
//设置或获取对象指定的文件名或路径。
alert(windowlocationpathname);
//设置或获取整个 URL
为字符串。
alert(windowlocationhref);
//设置或获取与 URL
关联的端口号码。
alert(windowlocationport);
//设置或获取 URL
的协议部分。
alert(windowlocationprotocol);
//设置或获取 href
属性中在井号“#”后面的分段。
alert(windowlocationhash);
//设置或获取 location 或 URL 的
hostname 和 port 号码。
alert(windowlocationhost);
//设置或获取 href
属性中跟在问号后面的部分。
alert(windowlocationsearch);
windowlocationhref 和 locationhref 是 JavaScript 中用来获取当前页面 URL 的属性,与 *** 作系统无关。因此,它们可以在任何 *** 作系统中使用,包括 Linux。
在 JavaScript 中,windowlocationhref 和 locationhref 是用来获取或设置当前页面 URL 的。如果你要在 JavaScript 中使用这些属性,你可以在任何支持 JavaScript 的浏览器或 *** 作系统中使用它们。
请注意,这些属性返回的 URL 通常是浏览器地址栏中显示的 URL,可能不包括当前页面的完整路径或文件名,因此您可能需要进行进一步的 *** 作来获取您需要的信息。
js中通过windowlocationhref和documentlocationhref、documentURL获取当前浏览器的地址的值,它们的的区别是:
1、document表示的是一个文档对象,window表示的是一个窗口对象,一个窗口下可以有多个文档对象。所以一个窗口下只有一个windowlocationhref,但是可能有多个documentURL、documentlocationhref
2、windowlocationhref和documentlocationhref可以被赋值,然后跳转到其它页面,documentURL只能读不能写
3、documentlocationhref和documentlocationreplace都可以实现从A页面切换到B页面,但他们的区别是:
用documentlocationhref切换后,可以退回到原页面。
而用documentlocationreplace切换后,不可以通过“后退”退回到原页面。
用ajax请求啊,给服务器 GET或者POST 当前HTML页面的的URL
我的例子是用的jquery
$get(geturlphp, //GET请求地址
{url : windowlocationhref}, //get请求参数。就相当于 geturlphpurl=>
js中通过windowlocationhref和documentlocationhref、documentURL获取当前浏览器的地址的值,它们的的区别是:
1、document表示的是一个文档对象,window表示的是一个窗口对象,一个窗口下可以有多个文档对象。所以一个窗口下只有一个windowlocationhref,但是可能有多个documentURL、documentlocationhref
2、windowlocationhref和documentlocationhref可以被赋值,然后跳转到其它页面,documentURL只能读不能写
3、documentlocationhref和documentlocationreplace都可以实现从A页面切换到B页面,但他们的区别是:
用documentlocationhref切换后,可以退回到原页面。
而用documentlocationreplace切换后,不可以通过“后退”退回到原页面。
以上就是关于如何获取跳转前页面的url-CSDN论坛全部的内容,包括:如何获取跳转前页面的url-CSDN论坛、"window.location.href"、"location.href在Linux中能实现吗、怎么获取Location的值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)