How can I load iOS webclip links in the same window?

2.5k views Asked by At

After loading up a Webclip with some links in it, clicking a link launches Mobile Safari instead of loading the link in the same window. Is there a way to prevent the link loading in Safari instead of the Webclip instance? I'm trying to mock up a mobile app just using PHP on my local Apache installation.

2

There are 2 answers

0
Tron5000 On BEST ANSWER

According to the Apple docs it looks like external page links will always open in Mobile Safari:

In this mode any external links will be opened in Safari on iPhone, meaning that you will have to keep your web application to a single page and use Ajax to update parts of that page.

0
alanaktion On

In addition to the option of using a single page loading new content with AJAX, you can use the JavaScript self.location=URL; return false on hyperlinks that must stay within the application. This can be added to the HTML code directly, or with another script upon loading the page.

If you are using jQuery, I would recommend something like this:

$('a:not([target])').click(function(){
    self.location = $(this).attr('href');
    return false;
});

Obviously this script should be ran after the HTML has loaded, to ensure that it actually attaches to the A elements onClick event.