本文介绍了PhoneGap InAppBrowser:打开iOS Safari浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的PhoneGap iOS应用程序中,我们使用InAppBrowser插件显示一些内容,我们需要在InAppBrowser中在Safari中打开一个页面。



我们可以从

在Safari中打开的InAppBrowser中建立链接。

解决方案 http://docs.phonegap.com/en/2.9.0/cordova_inappbrowser_inappbrowser.md.html#window.open =nofollow> phonegap documentation :

因此,要回答您的问题,请使用:

  window.open(your_url,'_system',opts); 

请注意,域名需要列入白名单。






更新4/25/2014:



我想我误解了这个问题评论者@peteorpeter) - 你想有一些方法点击InAppBrowser中的链接,并在系统浏览器中打开(例如iOS上的Mobile Safari)。这是可能的,但它需要应用程序开发人员和负责网页上的链接的人之间的一些预期和合作。



创建IAB实例时,获取对它的引用:

  var ref = window.open('http://foo.com','_blank ',{...}); 

您可以:

  ref.addEventListener('loadStart',function(event){...}); 

每当IAB的URL发生变化时触发此特定事件(例如,点击链接,服务器返回一个302等等),你可以检查新的URL。



为了进入系统浏览器,你需要一些定义的标志网址。你可以做任何事情,但是对于这个例子,我们假设在url中有一个 systemBrowser 标志:



..... html?foo = 1& systemBrowser = true



您将在事件处理程序中查找该标志,找到,跳到系统浏览器:

  ref.addEventListener('loadStart',function(event){
if(event.url.indexOf('systemBrowser')> 0){
window.open(event.url,'_system',null);
}
});

请注意,这不是 url(可能会导致误报),我很确定PhoneGap白名单规则仍然适用。


In our PhoneGap iOS application, we are using the InAppBrowser plugin to display some content, and we need to open a page in Safari from within the InAppBrowser.

How can we have links from within the InAppBrowser open in Safari?

解决方案

From the phonegap documentation:

So to answer your question, use:

window.open(your_url, '_system', opts);

Note that the domain will need to be white-listed.


Update 4/25/2014:

I think I kind of misunderstood the question (thanks to commenter @peteorpeter) -- you want to have some way to click a link in the InAppBrowser and have that open in the system browser (e.g. Mobile Safari on iOS). This is possible, but it will require some forethought and cooperation between the app developer and the person responsible for the links on the page.

When you create an IAB instance, you get a reference to it back:

var ref = window.open('http://foo.com', '_blank', {...});

You can register a few event listeners on that reference:

ref.addEventListener('loadStart', function(event){ ... });

This particular event is fired every time the URL of the IAB changes (e.g. a link is clicked, the server returns a 302, etc...), and you can inspect the new URL.

To break out into the system browser, you need some sort of flag defined in the URL. You could do any number of things, but for this example let's assume there's a systemBrowser flag in the url:

.....html?foo=1&systemBrowser=true

You'll look for that flag in your event handler, and when found, kick out to the system browser:

ref.addEventListener('loadStart', function(event){
    if (event.url.indexOf('systemBrowser') > 0){
        window.open(event.url, '_system', null);
    }
});

Note that this is not the best method for detecting the flag in the url (could lead to false positives, possibly) and I'm pretty sure that PhoneGap whitelist rules will still apply.

这篇关于PhoneGap InAppBrowser:打开iOS Safari浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 20:32