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

Java Development

Reply
Developer
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

BrowserField: Do actions according to URL

I have a browserfield on screen. While navigating in browserfield i want to track urls and for a perticular url i have to push another screen. How should i do this? 

Developer
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

Re: BrowserField: Do actions according to URL

Check with the following link

 

http://stackoverflow.com/questions/418105/embedded-html-control-for-blackberry

 

Some pointer keyword to search in Google


BrowserFieldController

RenderingApplication

extendScriptEngine

executeScript

 

 

 

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Developer
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: BrowserField: Do actions according to URL

It didnt help.
Contributor
Posts: 11
Registered: ‎03-23-2011
My Device: BlackBerry Bold
My Carrier: Verizon

Re: BrowserField: Do actions according to URL

[ Edited ]
//Attach a controller to the browser field		mBrowserField.getConfig().setProperty(BrowserFieldConfig.CONTROLLER, new BrowserController());


//Define actions to be done on URL calls
final class BrowserController extends ProtocolController{

private String URL_TO_TRAP = "http://us.blackberry.com/devices.html";		

     //Called when navigating to a new URL	
   public void handleNavigationRequest(BrowserFieldRequest request) throws Exception{
			
			if(request.getURL().equals(URL_TO_TRAP) ){
                               //custom action here
                         }

			super.handleNavigationRequest(request);		
     }
		
    //Called when the browser field is loading a resource(image, script etc)
    public InputConnection handleResourceRequest(BrowserFieldRequest request) throws Exception{
		
                        if(request.getURL().equals(URL_TO_TRAP) ){
                               //custom action here
                         }
			return super.handleResourceRequest(request);
     }		
}

 

You need to attach a controller to the browserfield and check every URL that is called. 

 

It is advisable to use "indexOf()" String comparison instead of equals to avoid clash with parameters within URL. 

e.g., you want to trap call to "http://us.blackberry.com/devices.html" but the actual call could be "http://us.blackberry.com/devices.html?lid=us:bb:devices&lpos=us:bb:devices"

 

Tell me this solved your problem! Smiley Happy

 

Developer
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: BrowserField: Do actions according to URL

[ Edited ]

thanx. I tried this with BrowserFieldListener. I got my solution.

Contributor
Posts: 11
Registered: ‎03-23-2011
My Device: BlackBerry Bold
My Carrier: Verizon

Re: BrowserField: Do actions according to URL

BrowserFieldListener events are called AFTER/DURING the Page is loaded. It might cause errors if you delete the screen that contains the BrowserField on loading a URL. Using a controller is a better approach if this is what you are doing since those methods are called before a URL is requested.
Developer
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: BrowserField: Do actions according to URL

i used it in documentCreated() method.
Highlighted
Developer
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: BrowserField: Do actions according to URL

Suppose i am on page sample.aspx in browserfield.When i am on this page and i press back button i want to display some other screen. How should i do it?