Marcelo Alves

Prevent Links From Escaping Full Screen App

Introduction

user

Marcelo Alves

Web developer living in Central California. Working with Ruby/Rails, Javascript, and dabbling in Elixir. Always searching for solutions that need problems.


notes ios pwa safari

Prevent Links From Escaping Full Screen App

Posted by Marcelo Alves on .
Featured

notes ios pwa safari

Prevent Links From Escaping Full Screen App

Posted by Marcelo Alves on .

After adding a site to your homescreen in iOS, Safari does this weird thing where links will end up opening up a new browser window. This snippet of javascript prevents that:

$(document).ready(function(){
  if(window.navigator.standalone == true) {
    $('a').click(function(e) {
      window.location = $(this).attr('href');
      return false;
    });
  }
});

However when using Bootstrap, dropdown links stop working. Adding something like this seems to solve the issue:

if($(e.target).hasClass('dropdown-toggle')) {
  return;
}
user

Marcelo Alves

http://marceloalves.com

Web developer living in Central California. Working with Ruby/Rails, Javascript, and dabbling in Elixir. Always searching for solutions that need problems.