HTML5 page and Android page pass parameters via URL

Source: Internet
Author: User

HTML5 page and Android page can pass parameters via URL, Android put parameters in Htm5 URL? After, js gets the URL? Parameter after the number.

Method One:

<scrīpt>

/* 用途: 接收地直栏参数 如取id=1 */

urlinfo=window.location.href; //获取当前页面的url

len=urlinfo.length;//获取url的长度

offset=urlinfo.indexOf("?");//设置参数字符串开始的位置

newsidinfo=urlinfo.substr(offset,len)//取出参数字符串 这里会获得类似“id=1”这样的字符串

newsids=newsidinfo.split("=");//对获得的参数字符串按照“=”进行分割

newsname=newsids[0];//得到参数名字,如id

newsid=newsids[1];//得到参数值

</scrīpt>

Method Two:

<script>

function Getrequest ()

{

var url = location.search;//Get URL in "?" String after the character

var therequest = new Object ();

if (Url.indexof ("?")! =-1)

{

var str = url.substr (1);

   STRs = Str.split ("&");

for (var i = 0; I < strs.length; i + +)

{

Therequest[strs[i].split ("=") [0]]=unescape (Strs[i].split ("=") [1]);

}

}

return therequest;

}

</Script>

then we get the corresponding parameter value by calling this function: <script> Varrequest=New Object (); request=getrequest (); var parameter 1, Parameter 2, parameter 3, parameter n; Parameters1=request[' parameter 1 ']; Parameters2=request[' parameter 2 ']; Parameters3=request[' parameter 3 ']; Parametersn=request[' parameter N '];  </Script>

HTML5 page and Android page pass parameters via URL

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.