1

I developed a small web app which runs perfectly in my browsers (Firefox, Chrome, Safari on iPad). Then I decided to modify the app so it runs as a standalone web app on my iPad. This was no problem as I found pretty good information on the web.

Because I'm using many app-internal links, I added the following JavaScript jQuery code to the app:

if (window.navigator.standalone) {
    // running as web app

    $(function () {
        $('a').each(function () {
            if (!$(this).hasClass('external')) {
                var href = $(this).attr('href');
                $(this).attr('href', 'javascript:this.location = \'' + href + '\'');
            }
        });
    });
}

In case the app is run in standalone mode, this code modifies all links which do not have the CSS class external so they won't open in a new Safari window. This code works fine.

The problem is that if I open a link that is external, a new Safari window opens (as expected). But when I switch back to my app (using the four-finger-gesture), the app is frozen: No scrolling, nothing clickable, no task switching, no five-finger-gesture anymore. When I press the Home button, the iPad shows my home screen for a split second, and then instantly switches to the iPad search screen. When I turn the screen off and on again, I'm on the home screen.

The only gesture that works is the four-finger-gesture to bring up the task bar (is that its name?). When I terminate the app using the task bar, it is still on the screen and the iPad behaves as if I hadn't terminated the app (see last paragraph). Feels like the app crahed in some crazy way.

I don't know what I've done wrong. It's a pretty simple web page with very few JavaScript and an HTML structure that is not deeply nested.

The device is an iPad 2 3G with iOS 5.1.

Can anyone help me with this?

fero
  • 6,050
  • 1
  • 33
  • 56

1 Answers1

1

So I gave this code before I read this link: iPhone Safari Web App opens links in new window

Did you try This answer ?


My previous answer:

if (window.navigator.standalone) {
  // running as web app

  $(function () {
    $('a').each(function () {
        if (!$(this).hasClass('external')) {
            var href = $(this).attr('href');
            $(this).click(function() { window.location = href; return false;});

        }
    });
  });
}
Community
  • 1
  • 1
mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • The `href` replacement is actually the second version of my JS code. The first one looked more like what you suggested. I changed it because I wanted to make sure wrong event handling isn't causing the error. An in-app link is something like `/?skip=50&order=title`, external links have different domains. – fero Apr 11 '12 at 19:53
  • But why have JS replacement at all of in-app links? Why not replace the EXTERNAL links with "sorry you are not online" alert if that is what you need – mplungjan Apr 11 '12 at 20:39
  • I'm not sure if you understood correctly what I mean with internal and external links. If you develop a standalone web app for iOS, the web app is not displayed in a normal browser window. It has the look and feel of a native app (if well programmed). But if you tap an ordinary link (no matter where it goes), iOS will open Safari to follow that link (that's what I call external). If you want to navigate to another page within your app, you will have to replace the URL of the current page using JavaScript. See [link](http://stackoverflow.com/questions/2898740/) – fero Apr 11 '12 at 21:01
  • Right. That is clear. Thanks. So what about my code which is identical to the link you gave apart from using jQuery syntax – mplungjan Apr 12 '12 at 06:13
  • None of the code snippets work - not my code, not your code, not the code you mention in your answer. I think this is a general multi-tasking problem on iOS. The problem in [this question](http://stackoverflow.com/questions/9114270/) seems to have the same cause. – fero Apr 12 '12 at 08:04