Tuesday, August 8, 2017

How open link in safari mobile app from webview

Leave a Comment

There are many topics of this here, but they all need native code interaction to work.

In my case, it is necessary to be able to do it directly from the url, without any interaction with my mobile app.

I tried:

<a href="safari://google.com" target="_blank">Open Google in Safari</a>

and

<a href="webkit://google.com" target="_blank">Open</a>

and based in this post.

<script>     $(document).on('click', 'a[target="_blank"]', function (ev) {       var url;        ev.preventDefault();       url = $(this).attr('href');       window.open(url, '_system');     });   </script> 

but nothing works.

Anyone have any idea how to fix this?

1 Answers

Answers 1

If this is running in safari it should comply with safari async call restrictions regarding popups as explained here.

You should fix your code so that the window open will be outside the function, Something like that:

    <script>     var windowReference = window.open();      $(document).on('click', 'a[target="_blank"]', function (ev) {       var url;        ev.preventDefault();       url = $(this).attr('href');       windowReference.location = url;     });   </script> 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment