简体   繁体   中英

How to add parameter to url in javascript?

Hi am developing web application with javascript. I have one url to be clicked. Using query string i am getting params and i am trying to bind it to url as below.

 function getParameterByName(name, url) { if (!url) url = window.location.href; name = name.replace(/[\\[\\]]/g, "\\\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\\+/g, " ")); } var foo = getParameterByName('guid'); alert(foo); 
 <!doctype html> <html> <head> <meta name="viewport" content="width=device-width" /> <meta http-equiv="X-UA-Compatible" content="IE=8" /> <title>ScannerView</title> </head> <body> <div> <iframe src="http://Scanner.aufytech.com/C3CKYC Scanner.xbap?param1=foo" width="1000" height="600" scrolling="auto"></iframe> </div> </body> </html> 

My foo variable contains required values. But when i append p?param1=foo it gives me empty value! May i know is there any way to fix this? Any help would be appreciated. Thank you.

very simple:

history.pushState({}, "title", "?page=1");

url from test.com change to test.com/?page=1

browser support

Feature     Chrome  Edge    Firefox (Gecko) IE  Opera   Safari
pushState   5       (Yes)   4.0 (2.0)       10  11.50   5.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM