PhoneGap InAppBrowser:打开iOS Safari浏览器 [英] PhoneGap InAppBrowser: open iOS Safari Browser

查看:391
本文介绍了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 :


在新的InAppBrowser实例,当前浏览器实例或系统浏览器中打开一个URL。

  var ref = window.open(url,target,options); 




  • ref:对InAppBrowser窗口的引用。 (InAppBrowser)

  • url:要加载的网址(String)。

  • target:要加载网址的目标,默认为_self的可选参数。如果URL包含Unicode字符,则调用encodeURI (String)




    • _self:如果URL位于白名单中,则在Cordova WebView中打开,否则将在InAppBrowser中打开。 li>
    • _blank:在InAppBrowser中打开。

    • _system:在系统的网络浏览器中打开。

    li>

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

  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:

Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser.

var ref = window.open(url, target, options);

  • ref: Reference to the InAppBrowser window. (InAppBrowser)
  • url: The URL to load (String). Call encodeURI() on this if the URL contains Unicode characters.
  • target: The target in which to load the URL, an optional parameter that defaults to _self. (String)

    • _self: Opens in the Cordova WebView if the URL is in the white list, otherwise it opens in the InAppBrowser.
    • _blank: Opens in the InAppBrowser.
    • _system: Opens in the system's web browser.

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浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆