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

Web and WebWorks Development

Reply
Contributor
Posts: 21
Registered: ‎04-23-2011
My Device: 9700
My Carrier: xl

executeScript() not work help me pleaseeeee ....

What's wrong .... I try execute  javascript  from extension but  not work

here my code

 

 

	 private BrowserField _browserField;
	   public Object invoke(Object obj, Object[] args) throws Exception
	   {
		   
		 
     
          _browserField.getScriptEngine().executeScript("socketMessagex()",null);
	
	   return UNDEFINED;
	   }

}

 

 

I ready see this link but still no luck

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Initialize-BrowserField-object-i...

 

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Widget-Javascript-Extension-Call...

 

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Widget-Javascript-Extension-Call...

 

 

 

 

Contributor
Posts: 21
Registered: ‎04-23-2011
My Device: 9700
My Carrier: xl

Re: executeScript() not work help me pleaseeeee ....

Does anybody can help me..??

Developer
Posts: 164
Registered: ‎08-26-2010
My Device: Not Specified

Re: executeScript() not work help me pleaseeeee ....

 


sondang wrote:

Does anybody can help me..??


 

looks like you did a mistake scripts,

you should be refer to the Solution post by tneil in the referred thread above..

Contributor
Posts: 21
Registered: ‎04-23-2011
My Device: 9700
My Carrier: xl

Re: executeScript() not work help me pleaseeeee ....

I try this still not work

 

 

public final class SocketFunction extends ScriptableFunction {
	
	 private BrowserField _browserField;
	   public Object invoke(Object obj, Object[] args) throws Exception
	   {
	    
	         ScriptableFunction socketMessagex = (ScriptableFunction)args[3];
	         socketMessagex.invoke(socketMessagex, null);
       
		   return UNDEFINED;
	   }

Please help my can you give me example ?

 

This my javascript code in head2

 

 

function socketMessagex(){
alert("fungtion socketMessagex execute");
}

 

 

Contributor
Posts: 21
Registered: ‎04-23-2011
My Device: 9700
My Carrier: xl

Re: executeScript() not work help me pleaseeeee ....

And Im using socket connection in extension if server push messages will execute javascript socketMessagex(msg)

my code going like this :

 

 

import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.script.ScriptableFunction;
public final class SocketFunction extends ScriptableFunction {
    private static String URL = "socket://192.168.1.105:8790;deviceside=false";
	private BrowserField _browserField;
	   public Object invoke(Object obj, Object[] args) throws Exception
	   {
		   _browserField.executeScript("socketMessagex('mmm')");
		   /*
		   StreamConnection conn = null;
		   	conn = (StreamConnection)Connector.open(URL);
		   	
		   	OutputStreamWriter _out = new OutputStreamWriter(conn.openOutputStream());
		   	String data = "This is a test --->";
		   	_out.write(data);
		   	
		   	InputStreamReader _in = new InputStreamReader(conn.openInputStream());
		   	StringBuffer sb = new StringBuffer();
		   	int c = 0;
	        while (((c = _in.read()) != '\n') && (c != -1)) {
	           sb.append((char) c);
	        }
	       // I want execute socketMessage function if server socket push data socketMessagex(" + sb.toString() + ")
	    
		   	_in.close();
		   	_out.close();
		   	conn.close();

		   	return UNDEFINED;
		 
	

}

 Please i need solution.... urgently ...

 

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: executeScript() not work help me pleaseeeee ....

have you made sure that your handle to browserfield isn't null? i see it declared but not assigned
Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Contributor
Posts: 21
Registered: ‎04-23-2011
My Device: 9700
My Carrier: xl

Re: executeScript() not work help me pleaseeeee ....

I try your sample code, but have error in [param1, param2]. I don't realy undestant. Can you give me example if I want to execute function socketMessages(msg){ alert('execute...');}

Thanks
Sondang
Developer
Posts: 285
Registered: ‎08-26-2011
My Device: 9900
My Carrier: Not Specified

Re: executeScript() not work help me pleaseeeee ....

[ Edited ]
import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.browser.field2.BrowserFieldConfig;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

import org.w3c.dom.Node;
import org.w3c.dom.html2.HTMLElement;
import org.w3c.dom.html2.HTMLScriptElement;

public class LoadingScreen extends MainScreen implements FieldChangeListener
{
	VerticalFieldManager vertical;
	HorizontalFieldManager hor;
	ButtonField click;
	String str,url;
	HTMLScriptElement script;
	HTMLElement element;
	Node node;
	BrowserField browserField;
	public LoadingScreen() 
	{				
		//str="<p align=center>ali shaik</p>";
		vertical=new VerticalFieldManager();
		url="local:///index.html";
		click=new ButtonField("click");
		click.setChangeListener(this);
		vertical.add(click);		
		//BrowserFieldConfig config=new BrowserFieldConfig();
		//config.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE);
		browserField=new BrowserField();	
		browserField.requestContent(url);		
		vertical.add(browserField);	
		add(vertical);
	}
	public void fieldChanged(Field field, int context) 
	{
		if(click==field)
		{			
			browserField.executeScript("add(5,45)");
		}
	}
}

 

 

and my html file:index.html(add to 'res' directory);
<html>
	<head>
		<script language="JavaScript">
			function add(a,b)
			{
			var i,j;
			i=a;
			j=b;
				alert("Calling Add Function:"+(i+j)); 
			}
		</script>
	</head>
<body bgcolor=green>
</body>
</html>

 It working. Check it once.

 

 ===========================================================================

feel free to press the like button on the right side to thank the user that helped you.

=================================================================================
Feel free to click LIKE button if the solution helps you;
--
Regards,

ALI SHAIK.
New Contributor
Posts: 2
Registered: ‎10-20-2011
My Device: BOLD 8900
My Carrier: CUGSM

Re: executeScript() not work help me pleaseeeee ....

Hi alishaik786, 

i've tried your code and it seems it's not working on OS6 but on OS5 the browserfield.executescript will run and pop-up the alert but once i click on the alert i will get an JVM error... any help here? 

New Contributor
Posts: 2
Registered: ‎10-20-2011
My Device: BOLD 8900
My Carrier: CUGSM

Re: executeScript() not work help me pleaseeeee ....

Ah ok i solve the JVM error it's that i didn't consume the buttonfield

click=new ButtonField("click", ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER );