1

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>
Michael Shimmins
  • 19,961
  • 7
  • 57
  • 90
mahesh
  • 3,067
  • 16
  • 69
  • 127

1 Answers1

5

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;
Michael Shimmins
  • 19,961
  • 7
  • 57
  • 90
  • 2
    dont forget to encode the ampersands in the URL, either with & instead of &, or by using window.location = encodeURI(url); – RPM1984 Sep 21 '10 at 05:03