Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
tbassetto
Posts: 16
Registered: ‎07-19-2012
My Device: BB10 dev alpha
My Carrier: Sosh (Orange subsidiary)

Is it possible to load local:///chrome/webworks.js dynamically?

Hi,

 

I tried to load webwork.js dynamically like this:

 

var script = document.createElement('script');

script.src='local:///chrome/webworks.js';
script.type= "text/javascript";

document.getElementsByTagName('head')[0].appendChild(script);

 

but then the webworksready event is never fired. It works if I put directly:

 

<script type="text/javascript" src="local:///chrome/webworks.js"></script>

 

Is there a way to load webwork.js conditionally? (only if the platform is BB)

 

Thanks.

Cross-device app developer.
Please use plain text.
BlackBerry Development Advisor
bryanhiggins
Posts: 201
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: Is it possible to load local:///chrome/webworks.js dynamically?

Hi, In that case, you need to register for webworksready after the script loads:

 

script.onload = function () {
    document.addEventListener("webworksready", function () {
        //do something
    });
};

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Please use plain text.
Contributor
tbassetto
Posts: 16
Registered: ‎07-19-2012
My Device: BB10 dev alpha
My Carrier: Sosh (Orange subsidiary)

Re: Is it possible to load local:///chrome/webworks.js dynamically?

Thanks, I'll try it if I encounter this problem again. In the meantime I've changed our build process to have an HTML file with a "classic" <script /> tag for BlackBerry OS 10.

Cross-device app developer.
Please use plain text.