开发者

$.mobile.changePage in jQuery Mobile - update visible URL?

I'm trying to add a changePage event in jQuery Mobile.

Basically I'd like to load a new page with a "pop" transition. Crucially I'd also like the displayed URL to update (so the user can link to the new page) and I'd like the page to appear in history.

Currently I'm trying:

 $('#mylink').click(function(){
    $.mobile.changePage('/photo.html?p=14545', { transition: "pop"} );
 });     
 <a id="mylink">Click here</a>

However, this isn't updating the displayed URL, and the page also doesn't seem to load correctly.

Any advice on how to make sure the URL is correctly upda开发者_运维百科ted and displayed?

Thanks!

UPDATE

note that this is an external URL, not a hash URL. I'm trying to find a way to go to the external page, and update the URL to that of the external page. Thanks!


Live Example: http://jsfiddle.net/r4DyU/1/

HTML:

<div data-role="page" data-theme="c" id="page1"> 
    <div data-role="content"> 
        <p>This is Page 1</p>
        <button type="submit" data-theme="a" name="submit" value="submit-value" id="submit-button-1">Open Dialog</button>
    </div>
</div>

<div data-role="page" data-theme="a" id="page2"> 
    <div data-role="content"> 
        <p>This is Page 2</p>
        <button type="submit" data-theme="e" name="submit" value="submit-value" id="submit-button-2">Close Dialog</button>
    </div>
</div>

JS:

$('#submit-button-1').click(function() {
    $.mobile.changePage($('#page2'), 'pop'); 
});

$('#submit-button-2').click(function() {
    alert('Going back to Page 1');
    $.mobile.changePage($('#page1'), 'pop'); 
});

// Or try this: Adding the URL
$('#submit-button-1').click(function() {
    $.mobile.changePage('/photo.html?p=14545', 'pop'); 
});

$('#submit-button-2').click(function() {
    alert('Going back to Page 1');
    $.mobile.changePage('/photo.html?p=14545', 'pop'); 
});


$.mobile.changePage("#yourpage", { dataUrl: "#yourpage?x=1&y=2", transition: "fade" });


In order to update the location hash you need to specify the new url in the changePage options paramter:

$.mobile.changePage('/photo.html?p=14545', {dataUrl: "/photo.html?p=14545", transition: "pop"});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜