Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I created a jquery mobile web app and on one of the buttons it links to an .HTML file. When I add the web app to my home screen and tap that button it opens the .HTML page in safari instead of staying within the app. I did some research online and came across this file but I still can't get it to work. Any ideas how to address this?

https://github.com/mrmoses/jQuery.stayInWebApp

share|improve this question
 
Did my answer work for you? –  Mike Barwick yesterday
 
Sorry but no... :( –  Automator21 yesterday
 
Any console errors? –  Mike Barwick yesterday
 
no nothing. Pages render as fine with the expect for the one that has the external link, that still opens up safari. I'll keep experimenting with it. –  Automator21 yesterday
 
It's an anchor link? Share all your code that applies to this. Your HTML and JS –  Mike Barwick yesterday
show 9 more comments

1 Answer

Here's what I use...applies to all anchors. To make a long story short, it's disabling each anchors default behaviour, grabbing the clicked anchor's href, and then using js to open the link within the web-app. Applied to mobile devices only.

<script>
$(function() {
    // prevent anchor links from opening in safari, web-app fix
    if (("standalone" in window.navigator) && window.navigator.standalone) {
        // For iOS Apps
        $('a').on('touchend click', function (e) {
            e.preventDefault(); return false;
            var new_location = $(this).attr('href');
            if (new_location != undefined && new_location.substr(0, 1) != '#' && $(this).attr('data-method') == undefined) {
                window.location = new_location;
            }
        });
    }
});
</script>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.