3

Im working on a jquery mobile project. I have two html pages. From index.html i have a swipeleft event to page.html and it works fine. From page.html i want to swiperight so i come back to index.html but that won't work.

The code works fine if i swipe between internal pages inside a single document, but not between html pages. And i need to use several html pages.

Has anyone got this to work? Would be grateful for answers.

This i my swipe code in my index.html page:

<script>
$(document).ready(function() {

$("#main").bind('swipeleft',function(event, ui){
        $.mobile.changePage("page.html", "slide");
})

})
</script>

And this is my code for my page.html:

<script>
$(document).ready(function() {

$("#main").bind('swiperight',function(event, ui){
        $.mobile.changePage("index.html", "slide");
})

})
</script>
gFat3
  • 29
  • 1
  • 2

3 Answers3

0

I am using following below code on all the pages to navigate on swipe its works fine on all the pages but their is no sliding animation.

$("#main").bind('swipeleft',function(event, ui){
      goPage1();
})
$("#main").bind('swiperight',function(event, ui){
      goPage2();
})  

function goPage1(){
   var dirPath = dirname(location.href);
   var fullPath = dirPath + "/page1.html";
   window.location=fullPath;
}

function goPage2(){
    var dirPath = dirname(location.href);
    var fullPath = dirPath + "/page2.html";
    window.location=fullPath;
}
function dirname(path){
    return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
}
Shashi
  • 1,165
  • 5
  • 20
  • 39
0

You should not use $.ready(), you should use pageInit() instead.
Also, be sure that all the ids on your pages are unique across all pages, not just unique for the page.

Ahmed Atia
  • 17,848
  • 25
  • 91
  • 133
0

Same question I have asked here.. jQuery Mobile - Swipe - Origin null not allowed by Access-Control-Allow-Origin

  1. You have to add after tags in every page.
  2. Instead of $.mobile.changePage(), I used location="index.html" and location="page.html". There is no sliding animation, but swiping happens.
Community
  • 1
  • 1
thandasoru
  • 1,558
  • 2
  • 15
  • 41