最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - How do i pass a javascript variable in querystring from one html page to other - Stack Overflow

programmeradmin0浏览0评论

I have two html pages example1.html and example2.html ,how can i pass a javascript variable username from example1.html to example2.html in querystring.

<script type="text/javascript" >
    $(document).ready(function() {
        $('#SubmitForm').submit(function() {
            var username = ($("#username").val());
               ...........
                ..........
              ..............
               .........

</script>
<body>
<div id="example2"><a href="http://localhost:1894/blockseek8-9-2010/example2.html?Var1=username" class="MainNav"></a></div>
</body>

I have two html pages example1.html and example2.html ,how can i pass a javascript variable username from example1.html to example2.html in querystring.

<script type="text/javascript" >
    $(document).ready(function() {
        $('#SubmitForm').submit(function() {
            var username = ($("#username").val());
               ...........
                ..........
              ..............
               .........

</script>
<body>
<div id="example2"><a href="http://localhost:1894/blockseek8-9-2010/example2.html?Var1=username" class="MainNav"></a></div>
</body>
Share Improve this question edited Sep 16, 2010 at 8:27 Delan Azabani 81.6k30 gold badges172 silver badges212 bronze badges asked Sep 16, 2010 at 8:26 maheshmahesh 3,21717 gold badges72 silver badges131 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

You can modify the href attribute of your link:

$("#example2 a").attr("href", url + "?var1=" + username);

If username uses special characters you will need to url encode it.

You could either use PHP, or set location.search.

What about using cookies? http://plugins.jquery./project/Cookie - no need to modify query string :)

发布评论

评论列表(0)

  1. 暂无评论