我需要在 Onsen 启动一个外部网站 Ui

I need to launch an external website in Onsen Ui

我需要在 Onsen Ui 中启动 外部 url / 网站而不离开应用程序。我可以在我需要的 ons-page 标签之间使用 iframe,但可能不太可靠。

这是我的第一个温泉 Ui 项目。

吉米

在OnsenUI上使用下面的方法即可

<a href="www.example.com">Link</a>

将销毁整个应用程序(网络视图)并将其替换为外部 HTML 资源。


解决方案:因此您可能需要 cordova-plugin-inappbrowser 插件的帮助。

在你的情况下, 在 Onsen Ui 中启动外部 url / 网站而不离开应用程序, 您需要“_self”或“_blank”(“_blank”用于以下示例代码)

// opts is optional depend on your requirements
var opts = 'location=yes';
var ref = cordova.InAppBrowser.open('http://www.example.com', '_blank', opts);

或者您可以使用 ngCordova 的 $cordovaInAppBrowser

angular.module('app')
    .controller('ctrl', ['$cordovaInAppBrowser', function($cordovaInAppBrowser) {
         var opts = {location: 'yes'};
         $cordovaInAppBrowser.open('http://www.example.com', '_blank', opts);
     }]);

我遇到了同样的问题,我使用了这个方法,它并不花哨,但对我有用

<a class="name" href="#" onclick="window.open('https://www.youtube.com/watch?v=_OOWhuC_9Lw', '_system', 'location=yes'); return false;">
      Watch
</a>