How to get links to open in the native browser in

2019-07-19 19:56发布

问题:

How do I prevent external links from opening in the in-app browser in apps built with Meteor for iOS? I want them to open in Safari instead.

回答1:

You'll need to download and install an apache cordova plugin to add this functionality into your meteor ios app.

Simply run this command into your terminal

meteor add cordova:cordova-plugin-inappbrowser@https://github.com/apache/cordova-plugin-inappbrowser/tarball/ba7cbe58d5812b51c3ece1

(here is a ref to the tarball/ba7cbe58d5812b51c3ece1) (use the latest commit to master branch)

Then simply add this into your meteor template to launch the system default browser app with the external link:

<a href="" onclick="window.open('http://www.example-url.com', '_system');">
Hope this helps!
</a>

Run: meteor run ios-device

(select your trusty simulator and test her out)



回答2:

Nick's answer to use the inappbrowser Cordova plugin is sound, but with the error you're seeing, make sure you're providing a full commit hash URL for the meteor tool/build to resolve. At the time of this writing, the correct Terminal command to use the latest commit is:

meteor add cordova:cordova-plugin-inappbrowser@https://github.com/apache/cordova-plugin-inappbrowser/tarball/bc9036d90a1f3f2220b5fc29b77cf2405e7fd781

The remaining steps are the same; use the _system target in your project's code for the link:

<a href="" onclick="window.open('http://external.url', '_system')">Open</a>

Then kick off a meteor build for your desired mobile platform and Cordova should apply the plugin without issue. Verified these steps work on Meteor 1.2.1.