简体   繁体   中英

IBM Worklight 6.0 - window.open() fails in BlackBerry 10

I had this working in Worklight 5, but I don't seem to be able to get it to work in V6.

I'm trying to use the Cordova InAppBrowser in my Worklight app on BlackBerry 10. My code is simple enough:

window.open(link, "_blank", "location=no");

This works on Android an iOS, but when II run it on the Blackberry 10 simulator, I get the following error in the console log:

POST http://localhost:8472/org.apache.cordova/isWhitelisted 404 (OK) 

config.xml for my app includes:

<access subdomains="true" uri="*" />

so all links should be whitelisted, but the 404 seems to be for the API call to check whether the link is whitelisted, not for the call to open the link.

If I muck with cordova.js to remove the whitelist check from the implementation of open(), the InAppBrowser suddenly works fine, but that file gets overwritten each time I build the app, so customizing it isn't an option.

Am I missing some configuration needed to make this work?

There seems to be a change in Cordova from 2.0 to 2.3. In Worklight V5, the wildcard whitelist access worked, but in V6 on BB10, only specific domains can be whitelisted.

If I add my specific domain as an access element in config.xml, suddenly window.open() works. Looking at the blackberry documentation , I think I see why

If you specify more than one element, the most specific definition is used. For example, if you use http://somedomain.com and http://specific.somedomain.com , the element that uses the first definition (and any features defined under it) is ignored.

But this leaves me wondering how the wildcard access worked in Worklight V5 (and it does) This same rule should apply to V5 Projects, and I don't see anything in the Cordova docs that changes, but for some reason the wildcard whitelist access works there but not in Worklight V6.

In any case, I can get window.open() to work so long as I specify all domains specifically in config.xml. I haven't found a way to successfully whitelist everything. I've tried to remove everything but:

<access subdomains="true" uri="*" />

(this matches what is in config.xml in my pure cordova test app)

But then the app fails connecting to the Worklight server (not quite sure why)

Worklight 6.0 uses Cordova v2.6, it could be that the support there for BlackBerry 10 in regards to window.open (which is now really InAppBrowser) is somewhat off.

See if you can play around with it based on the Cordova documentation:
http://cordova.apache.org/docs/en/2.6.0/cordova_inappbrowser_inappbrowser.md.html

I realize this question has already been answered, but there's a config.xml setting that you can add that will allow access to any domains, as documented here .

Just add:

<preference name="WebSecurity" value="disable"/>

To your config.xml and you should be good to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM