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
New Contributor
Daniel-H
Posts: 3
Registered: ‎01-27-2013
My Device: BB10

Launch Browser from Webview

Container{
        id: advertContainer
	background: Color.create("#2b2b2b")
        preferredHeight: 100.0
                
       //touchPropagationMode: TouchPropagationMode.PassThrough
       //touchPropagationMode: TouchPropagationMode.None
       //touchPropagationMode: TouchPropagationMode.Full
                
       horizontalAlignment: HorizontalAlignment.Fill
       WebView{
              id: adView

              touchPropagationMode: TouchPropagationMode.PassThrough
	             onNavigationRequested: {
			    console.log("NavigationRequested: " + request.url +  " navigationType=" + request.navigationType)
			    if (!shouldAcceptNavigationToUrl(request.url)) {
				        request.action = WebNavigationRequestAction.Ignore
				        invokeBrowser.trigger("bb.action.OPEN")
				        invokeQuery.uri = request.url
			    }
		    }
                    url: "local:///assets/advert.html"
                    horizontalAlignment: HorizontalAlignment.Center
               }
	} // end of advertContainer
 	attachedObjects: [
                Invocation {
                    id: invokeBrowser
                    query: InvokeQuery {
                         id: invokeQuery
                         invokeTargetId: "sys.browser"
                    }
                }
          ]

Hi,

 

I'm trying to launch the browser from webview when a link in the webview is clicked.

 

I dont want the webview to change at all when the link is clicked, only for the external browser to be launched and open the link clicked in Webview.

 

The above code is where I am at the moment.

 

I would be greatfull for any advice on how to proceed.

 

Regards

 

Dan

Please use plain text.
BlackBerry Development Advisor
shaque
Posts: 235
Registered: ‎07-14-2008
My Device: Not Specified

Re: Launch Browser from Webview

Hi,

Did you change the action property of the WebNavigationRequest or call WebNavigationRequest::ignore() ?

 

More details in the docs for 

WebView::navigationRequested (..)

 

Shadid

Please use plain text.
New Contributor
Daniel-H
Posts: 3
Registered: ‎01-27-2013
My Device: BB10

Re: Launch Browser from Webview

I got it working as follows:

 

            Container {
                id: advertContainer
                background: Color.create("#2b2b2b")
                preferredHeight: 100.0
                horizontalAlignment: HorizontalAlignment.Fill
                WebView {
                    id: adView
                    url: "local:///assets/advert.html"
                    horizontalAlignment: HorizontalAlignment.Center
                    onNavigationRequested: {
                        if (request.url == "local:///assets/advert.html") {
                            request.action = WebNavigationRequestAction.Accept
                        } else {
                            request.action = WebNavigationRequestAction.Ignore
                            invokeQuery.uri = request.url
                            invokeBrowser.trigger("bb.action.OPEN")   
                        }
                    }
                }
                attachedObjects: [
                    Invocation {
                        id: invokeBrowser
                        query: InvokeQuery {
                            id: invokeQuery
                            invokeTargetId: "sys.browser"
                            onQueryChanged: invokeQuery.updateQuery();
                        }
                    }
                ]
            }            // end of advertContainer

 

 

This part isnt in the docs:

                            invokeTargetId: "sys.browser"
                            onQueryChanged: invokeQuery.updateQuery();

 

 

Just to recap, this allows the opening of a link in webview to be launched in the broswer instead of the webview, leaving the webview unchanged.

Please use plain text.