【问题标题】:Opening all outside-app links in a system browser在系统浏览器中打开所有外部应用程序链接
【发布时间】:2017-02-23 01:34:22
【问题描述】:

我有一个 Ionic 1 应用程序,它通过 ngMap 指令包含 Google 地图。这很好用。

不适合的是,当用户点击地图中的“Credits”元素并且整个应用程序被重定向到 Google 地图积分页面时 - 因为它是一个 Ionic 应用程序,用户无法返回。

Ionic / Angular(不是 jQuery)中是否有办法拦截此类任意链接,以便它们在应用内或系统浏览器中打开?

【问题讨论】:

    标签: javascript ionic-framework ng-map


    【解决方案1】:

    通常是这样完成的:

    http://codepen.io/anon/pen/MpgrdN

    function isExternal(href) {
      return true;
    }
    document.body.addEventListener('click', function(e) {
      var maybeA = $(e.target).closest('a');
      if (maybeA.length && isExternal(maybeA[0].getAttribute('href'))) {
          // window.open()
          console.log('prevented');
          e.preventDefault();
      }
    });
    

    使用 jQuery closest 函数,如果没有 jQuery on page 独立实现在这里DOM / pure JavaScript solution to jQuery.closest() implementation?

    【讨论】:

      猜你喜欢
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 2022-08-04
      • 2014-09-02
      • 2018-07-06
      • 1970-01-01
      • 2013-11-29
      • 1970-01-01
      相关资源
      最近更新 更多