How to pass javascript variables from one html page to other html page

不羁的心 提交于 2019-12-01 11:54:03

问题


I have the following code to pass variable from example1.html to example2.html , what will be the syntax in window.location.href to navigate to example2.html with username and keyword.

example1.html

<script type="text/javascript">
    var username = ($("#username").val());
    var keyword = ($("#keyword").val());

    $("#button1").click(function(){
         window.location.href = "http://localhost:2757/example2.html";
    });
</script>

回答1:


If you want to pass them by query string parameters you can do this:

window.location = "http://localhost:2757/example2.html?username=" + username + "&keyword=" + keyword;


来源:https://stackoverflow.com/questions/3757372/how-to-pass-javascript-variables-from-one-html-page-to-other-html-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!