Four JS get address bar parameter instance function

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags .url access address address bar ajax data document function

This article has a collection of four JS access to the address bar parameter instance functions, they will use the splite to take? The parameters behind, and then split to separate & back parameters Oh, save to the data and then processed OH.

<script language= "Web Effects" >
var Url=window.location.search;
if (url.indexof)! =-1)
{
var str = URL.SUBSTR (1)
STRs = Str.split ("&");
for (i=0;i<strs.length;i++)
{
document.write ([Strs[i].split ("=") [0]], ' = ', unescape (strs[i].split ("=") [1]), ' <br> ';
}
}else document.write (' no parameters ');

</script>
Method Two

<script type= "Text/javascript" >

<!--

function request (strname) {

var strhref = "www.jzread.com/index.html?id=1&c=2";

var intpos = Strhref.indexof ("?");

var strright = strhref.substr (intpos +);

var arrtmp = Strright.split ("&");

for (var i = 0; i < arrtmp.length i) {

var arrtemp = arrtmp[i].split ("=");

if (arrtemp[0].touppercase () = = Strname.touppercase ()) return arrtemp[];

}

Return "";

}

Alert (Request ("a"));

Alert (Request ("B"));

Alert (Request ("C"));

-->

</script>

Method Three

<script language= "JavaScript" >
var id= ';
var Url=window.location.search;
if (url.indexof)! =-1)
{
var str = URL.SUBSTR (1)
STRs = Str.split ("&");
for (i=0;i<strs.length;i++)
{
if ([Strs[i].split ("=") [0]]== ' id ') id=unescape (strs[i].split ("=") [1]);
}
}
</script>
Method Four

<script type= "Text/javascript" >
function Urlsearch ()
{
var Name,value;
var str=location.href; Get the entire address bar
var num=str.indexof ("?")
Str=str.substr (num+1); Get all parameters
var arr=str.split ("&"); Each parameter is placed in an array
for (Var i=0;i < arr.length;i++) {
Num=arr[i].indexof ("=");
if (num>0) {
Name=arr[i].substring (0,num);
Value=arr[i].substr (num+1);
This[name]=value;
}
}
}
var request=new urlsearch (); Instantiated
alert (request.id);
</script>
For example, save this code as 1.html.

So I'm going to visit 1.html?id=test.

This is the time to get the test value.


Call in HTML

<script type= "Text/javascript" >
var a= "http://jzread.com";
</script>
</head>
<body>
<a id= "A1" href= "" >sadfsdfas</a>
<script>
var A1=document.getelementbyid ("A1");
A1.href=a;
</script>

<script type= "Text/javascript" >
var a= "HTTP://WWW.AIMEIGE.COM.CN?CCTV";
var s=a.indexof ("?");
var t=a.substring (s+1);/T is what's behind it. </script>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.