te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - How open link in safari mobile app from webview - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How open link in safari mobile app from webview - Stack Overflow

programmeradmin4浏览0评论

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" target="_blank">Open Google in Safari</a>

and

<a href="webkit://google" 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?

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." target="_blank">Open Google in Safari</a>

and

<a href="webkit://google." 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?

Share Improve this question asked Jul 28, 2017 at 17:05 jose920405jose920405 8,0596 gold badges47 silver badges75 bronze badges 4
  • I think the url scheme should be -apple-mobilesafari-tab://. – Etienne Martin Commented Aug 3, 2017 at 15:53
  • Is this a cordova/phonegap app? – catbadger Commented Aug 8, 2017 at 15:47
  • @catbadger it's not relevant, because i don't need any code from mobile app. – jose920405 Commented Aug 8, 2017 at 16:26
  • -apple-mobilesafari-tab no longer works as of ios 17.5 – ina Commented Jun 15, 2024 at 1:29
Add a ment  | 

3 Answers 3

Reset to default 7

There is a trick. We know iOS Safari have these available URL Schemes:

(HTTP) — http://websiteurl (HTTPS) — https://websiteurl x-web-search:// (FTP) — ftp://locationtofileonftpserver

If you use Click here or window.open("http://somewebsite"). It always use current browser to open url.

x-web-search://?[keyword] - It will switch into Safari app but search for the keyword

Luckily we still have ftp:// left. It will switch to Safari app. But first you need to setup a public folder in your hosting & create a bridge html file to redirect user back to http:

ftp://{youripaddress}/bridge.html

window.open("https://yoururl", "_self");

Now you can open your website in the default Safari app from any browsers.

The original answer is here: JS - Mobile - Open Safari from any browser


Update (2021-01): Apple seems to fix this on iOS, this is no longer work!

If this is running in safari it should ply 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>

There isn't a URL Scheme for Safari on iOS.

See Apple's Documentation: https://developer.apple./library/archive/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html

Have a search around and you will see similar answers: What is Mobile Safari's custom URL Scheme?

发布评论

评论列表(0)

  1. 暂无评论