Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Js gets the values in the page url

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

First, obtain the parameters through _ window.location

1. Get the complete url of the page

Url = _ window.location.href

2. Get the domain name of the page

Host = _ window.location.host

Host2=document.domain

Application scenario: the page jumps, and the domain names of the development environment and the test environment are different, so you need to dynamically obtain the url that is stitched and redirected.

2. Javascript regularly acquires the parameters in url. 1. Obtain parameters through substr and split.

/ / canonically get the parameter function URL_Request (strName) {var strHref = _ document.location.toString () in url; var intPos = strHref.indexOf ("?"); var strRight = strHref.substr (intPos + 1); / / = get the parameter part on the right var arrTmp = strRight.split ("&"); / / = split into an array for (var I = 0; I < arrTmp.length) by Circular array {var dIntPos = arrTmp [I] .indexOf ("="); var paraName = arrTmp [I] .substr (0, dIntPos); var paraData = arrTmp [I] .substr (dIntPos + 1); if (paraName.toUpperCase () = = strName.toUpperCase ()) {return paraData;}} return ";}

Use:

Var pbtradeId=URL_Request ("tradeId"); 2. Get [update20170503] through split

Function getQueryString (str, key) {if (str) {var queryString = str.split ('?) [1] | |'; var arr = queryString.split ('&') | | []; for (var I = 0; I)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report