You can do something like this:
$('#photo').ready(function () { var photoId = window.location.hash.replace("#photo", ""); $("#myphoto").attr("src", "http://dummyimage.com/600x400/000/" + photoId); window.location.hash = "#photo"; });
This will force jQuery to go to the #photo page, however, you must disconnect jQuery mobile from trying to download #photofff . This causes a quick flash on the page that an error occurred while loading the page, and then redirected to the correct #hash tag.
Update
If you disable hash tracking on this page, you can remove the display of the error message.
<script type="text/javascript"> $.mobile.hashListeningEnabled = false; </script> $('#photo').ready(function () { var photoId = window.location.hash.replace("#photo", ""); $("#myphoto").attr("src", "http://dummyimage.com/600x400/000/" + photoId); $.mobile.changePage("#photo"); });
Mark coleman
source share