简体   繁体   中英

passing data between pages in jquery mobile

I have looked at this post Here and it looks like a simple way of getting a querystring, but Is there a easy way of doing this with the jquery mobile framework? thanks for any advice

#MobileHomePage?param1=data&param2=data1

Passing data between pages with jQuery Mobile is very simple just use this function

$.urlParam = function(name){
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    return results[1] || 0;
}

for multi-page template use the following code :

$('#myPage').live('pageshow', function(event, ui) {
    var param = $.urlParam('param1');
    alert(param);
});

And for a normal template use :

    var param = $.urlParam('param1');
    alert(param);

And call the page like that :

www.yourwebsite.com/mypage?param1=test&gift=Candy etc...

make a jquery plugin for this.

    (function( $ ){

  $.fn.queryStrings = function( string ) {        

        var url = /[^?]*$/.exec(window.location.href)[0].split('&');

        var obj = {};

        url.forEach(function(url) {
            var tup = url.split('=');
            obj[tup[0]] = tup[1];
        });

        if (string) return obj[string];

        return obj;
  };
})( jQuery );

use like this:

$().queryStrings('myparam')

or

$().queryStrings()

to return all

There is currently no built in way of passing data between JQM pages, you can use the approaches outlined in the answers to the question you linked.

You might also want to look at these SO overflow questions

How-to store variable beetween jQM pages?

How to pass button text to another page?

If your asking how to navigate to the url you posted then you can just use $.mobile.changePage("#MobileHomePage?param1=data&param2=data1 ");

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