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

Native Development

Reply
Developer
Posts: 669
Registered: ‎02-19-2011
My Device: BlackBerry PlayBook 32GB
My Carrier: Sprint

postMessage between different webViews

I'm having the hardest time with postMessage. Is there any way to send a message and have it picked up by anything that's listening. Is there any way to post messages that get picked up by all WebViews in an app?

Staff UI Prototyper (read: full-time hacker)


My BB10 apps: Screamager | Scientific RPN Calculator | The Last Weather App

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: postMessage between different webViews

There's no "magic" builtin way of doing that, but using signals is the next best thing to magic. You could do something like add a "signal msgToWebViews()" in your root component, and emit that when you need to send out the required information. In each WebView that you create, add an onCreationCompleted handler and connect a function to that signal. If postMessage() by itself is sufficient, you could connect it directly like "root.msgToWebViews.connect(postMessage)" and it will be called any time the signal is sent. (You can work out what data you need to send with the signal for yourself, I'm sure.)

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 669
Registered: ‎02-19-2011
My Device: BlackBerry PlayBook 32GB
My Carrier: Sprint

Re: postMessage between different webViews

Are there any examples of this? I don't quite understand the above Smiley Sad

Staff UI Prototyper (read: full-time hacker)


My BB10 apps: Screamager | Scientific RPN Calculator | The Last Weather App

Developer
Posts: 669
Registered: ‎02-19-2011
My Device: BlackBerry PlayBook 32GB
My Carrier: Sprint

Re: postMessage between different webViews

Also, when trying it anyway even though I don't really understand it I got an error.

 

I have in my created page:

 

            onCreationCompleted: {

                 root.msgToWebViews.connect(postMessage);   

            }

 

When it gets created I get:

 

file:///apps/nl.imarco.rpnca
lculatorbb10.testDev_culatorbb10d2e79b54/native/assets//StackExplorerPage.qml:17: ReferenceError: Can't find variable: root

Staff UI Prototyper (read: full-time hacker)


My BB10 apps: Screamager | Scientific RPN Calculator | The Last Weather App

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: postMessage between different webViews

TheMarco, by convention many people put "id: root" on their top-level component in the app, be it a NavigationPane, or Page, or whatever. That makes it a simple matter to throw app-global signals in there, such as I described above, and you can reference that top-level component from almost everywhere with extra work. Try that and you should get past the above error.

I'm not aware of examples of just what I described... made it up on the spot.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!