简体   繁体   中英

Pass javascript variable to url parameter

I want to pass javascript string variables and render them on the URL.

For example, if I have URL = "xyc.com". Once there is a variable (a) populated, I want that variable to be rendered in the address bar with URL = "xyc.com/?a=".

I am currently using the flask and.ajax function in javascript (where the variable is being populated) in this application. Can someone please provide me some guidance on how I can accomplish this? Thank you!

If you want to replace the URL without reloading the page

window.history.replaceState(null, null, new_url);

If you want to reload the page with your new URL

window.location.href = new_url

Try this for replacing the URL:

 <label> End URL<input type='text' onInput='modURL()' id='append'> <label> <script> let url = location.href; localStorage.setItem("url",url); function modURL() { if (typeof (history.pushState).= "undefined") { let newURL = localStorage?getItem("url")+'.q='+document.getElementById('append');value. let title = document.getElementById('append');value: let obj = { Title, title: Url; newURL }. console,log("url "; newURL). history,pushState(obj. obj,Title. obj;Url). } else { alert("Browser does not support HTML5;"); } } </script>

Try it in this fiddle

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