0

With JQuery Mobile and MVC3 ASP.NET, on an iPad, created a home screen bookmark. The app pulls up with no problems, it does not show safari's bar. I login to my app and click a link, THE LINK OPENS SAFARI, NOT INTENDED.

My question is how to prevent the clicked link from opening outside of my bookmarked app? I've tried:

$(document).bind("pageinit", function () {
    $("a").click(function (e) {
        e.preventDefault();
        $.mobile.changePage($(this).attr('href'));
    });
});

The code above seems like it should work based on the docs from jquery mobile. When I click the link/button the link/button highlights but no error or page load.

Also, another question is why when I leave the app and come back the session dies?

Jason Foglia
  • 2,414
  • 3
  • 27
  • 48

2 Answers2

0

Is this webpage you are linking to being packaged with the app? You need to do so. The app cannot find it and goes out to the browser.

The code itself is fine. http://jsfiddle.net/m35BU/5/

Session variables are stored on a server...are you talking about a javascript cookie?

If so, unless you set an expiration date for the cookie (mktime()+3600*7 for 7 days) or whatever, it will expire when the app is closed.

Cymbals
  • 1,164
  • 1
  • 13
  • 26
0

iOS will treat links where you have stipulated data-ajax="false" as a link that should be opened by Safari. I had the same problem in my MVC site that is using jQueryMobile. I found this post very helpful and the following piece of code works very well in my application.

$("a[data-ajax='false']").live("click", function (event) {
    if (this.href) {
        event.preventDefault();
        location.href = this.href;
        return false;
    }
});
Community
  • 1
  • 1
macou
  • 777
  • 8
  • 21