It seems like this would be the best solution - from the jQuery Mobile demos.
Basically you configure the http header in your redirect and watch it on pagecontainerload . This should avoid weirdness with browser history.
Here a a href to go to the page
<a href="redirect.php?to=redirect-target.html" data-role="button" data-inline="true">Redirect</a>
In PHP you do it
<?php // ************************************************************************ // The two-second sleep simulates network delays, hopefully causing a // loading indicator message to appear on the client side. // ************************************************************************ sleep(2); $dst = ( isset( $_GET[ "to" ] ) ? $_GET[ "to" ] : ( isset( $_POST[ "to" ] ) ? $_POST[ "to" ] : false ) ); if ( $dst ) { // ********************************************************************** // The crucial line: Issue a custom header with the location to which the // redirect should happen. For simplicity, we simply redirect to whatever // location was specified in the request "to" parameter, but real-world // scripts can compute the destination based on server-side state. // // NB: This is not a HTTP redirect. As far as HTTP is concerned, this is // a normal request/response cycle with a status code of 200. // ********************************************************************** header( "X-Redirect: " . $dst ); } ?>
Then in your javascript you will do this to intercept the url and reset it.
$( document ).bind( "pagecontainerload", function( e, triggerData ) {
Note: at the time of writing this demo page, there was an incorrect link to the jquery demo page, so I had to find it on github
https://github.com/jquery/jquery-mobile/blob/master/demos/navigation-php-redirect/index.php https://github.com/jquery/jquery-mobile/blob/master/demos/navigation -php-redirect / redirect.php
The demo for 1.3 is still working http://demos.jquerymobile.com/1.3.0/docs/examples/redirect/
Simon_Weaver
source share