将javascript变量传递给url参数 [英] Pass javascript variable to url parameter
问题描述
我想传递 javascript 字符串变量并在 URL 上呈现它们.
I want to pass javascript string variables and render them on the URL.
例如,如果我有 URL = xyc.com".一旦填充了一个变量 (a),我希望该变量在地址栏中呈现,URL = "xyc.com/?a=";.
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=" .
我目前在此应用程序中使用 javascript(填充变量的位置)中的 flask 和 .ajax 函数.有人可以为我提供一些有关如何完成此操作的指导吗?谢谢!
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!
推荐答案
如果你想在不重新加载页面的情况下替换 URL
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
这篇关于将javascript变量传递给url参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!