03-23-2010 04:28 PM
Hey guys, wondering if any one can help me out or give a little guidance on this issue.
I have a local html string that I am displaying on a screen inside of a BrowserField object, and what I want to do is have any link inside the field that is clicked to open the link inside of an actual browser session. I looked through the API for an method to override that handles the links but didnt see one, although I could have just missed it. Any suggestions?
Thanks
Kyle
Solved! Go to Solution.
03-24-2010 01:27 AM
Looking for something similar, has anyone done this? or even override the navigation click?
04-27-2010 02:37 AM
Alright, so in the 5.0 API there is a method getController() in the BrowserField class that returns a BrowserFieldController object, which subsequently has a handleNavigationRequest which is what I would assume you would want to use if you wanted to intercept the link press. Does anyone know how to override this and apply it to the browser field? There is no set method for the controller so I havent found a way.
04-27-2010 07:18 AM
There was a nice implementation by someone, can't remember though. If you search the forums you can find it. It works in the API's below 5.0 ![]()
06-28-2010 10:39 PM
Hey Guys,
I know this thread has been dormant for a while but I found the solution so I thought id post her if anyone else ever has the same issue.
BrowserFieldConfig bfc = new BrowserFieldConfig(); bfc.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_CARET); bfc.setProperty(BrowserFieldConfig.CONTROLLER, new BrowserFieldController(){ public InputConnection handleResourceRequest(BrowserFieldRequest request) throws Exception { return (InputConnection)Connector.open(request.getURL()); } public void handleNavigationRequest(BrowserFieldRequest request) throws Exception { BrowserSession b = Browser.getDefaultSession(); b.displayPage(request.getURL()); } }); bf = new BrowserField(bfc);
10-09-2010 06:25 PM - edited 10-09-2010 07:30 PM
I tried the code above, but what I got was that all content was opened in the full-fledged browser. I was wanting to display local HTML content in my BrowserField, and if the user followed links from inside that content, to external HTTP sites, then I wanted to spawn the browser. Here's how I acheived that, instead of the code above.
BrowserFieldConfig fieldConfig = new BrowserFieldConfig();
fieldConfig.setProperty(BrowserFieldConfig.NAVIGAT ION_MODE, BrowserFieldConfig.NAVIGATION_MODE_POINTER);
_browserField = new BrowserField(fieldConfig);
// Use the default (full-featured) browser to view external http content
ProtocolController hybridController = new ProtocolController(_browserField);
hybridController.setNavigationRequestHandler("http ",
new BrowserFieldNavigationRequestHandler() {
public void handleNavigation(BrowserFieldRequest request) {
BrowserSession browser = Browser.getDefaultSession();
browser.displayPage(request.getURL());
}
});
_browserField.getConfig().setProperty(BrowserField Config.CONTROLLER, hybridController);
add(_browserField);
Of course, if you also want HTTPS content handled this way, I'm guessing you need to add another call to setNavigationRequestHandler, for "https". But, you get the idea.
10-29-2010 02:04 PM
It's easy n8r0n:
Instead of:
BrowserSession browser = Browser.getDefaultSession(); browser.displayPage(request.getURL());
use:
_browserField.requestContent(request);
10-29-2010 10:02 PM
Please read the original question. He (and I) didn't want to open up content inside of the BrowserField itself. We wanted to spawn the external Browser to open content when links are clicked.
Your code does not do that.