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
Highlighted
New Contributor
Posts: 9
Registered: ‎07-04-2011
My Device: bold 9870
My Carrier: jojo
Accepted Solution

javascript browser field

i need to execute a javascript in broswer field 

BrowserFieldConfig config = new BrowserFieldConfig();
config.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE); BrowserField br = new BrowserField(config); add(br); br.executeScript("<html><body><script type='text/javascript'>document.write('Hello World!')</script> </body</html>");

 


but doesn't work  

 


New Contributor
Posts: 9
Registered: ‎07-04-2011
My Device: bold 9870
My Carrier: jojo

Re: javascript browser field

i tried also

config.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE);

BrowserField br = new BrowserField(config);

add(br);

br.getScriptEngine().executeScript("<html><body><script type='text/javascript'>document.write('Hello World!')</script> </body</html>",null);

 

 but get this java.lang.NullPointerException

????


New Contributor
Posts: 8
Registered: ‎06-02-2011
My Device: bold 9870
My Carrier: java developer

Re: javascript browser field

HTMLScriptElement script =(HTMLScriptElement)br.getDocument().createElement("script");script.setType("text/javascript");

script.setSrc("script2.js");

Node headNode = br.getDocument().getElementsByTagName("head").item(0);
headNode.appendChild(script);
String name ="test4";

br.executeScript( "function('"+name+"')" )

 

this code add external javascript to your document 

you can put in it any javascript function