ExecuteJavaScript() in JCEF

Having problems with building or using the JCEF Java binding? Ask your questions here.

ExecuteJavaScript() in JCEF

Postby ramyakrishnan » Tue Sep 22, 2015 10:26 am

Hi,

I am new to JCEF and I am in the process of trying to send some input values from my Java code to the Javascript code for the HTML loaded on my jcef browser and trying to execute the Javascript code with the arguments I send from my Java code. I came across a function called executeJavaScript() for doing this but somehow I do not understand how to use this code in my application (as nothing happens in my code) ..

I tried it as simple as this browser.executeJavaScript("alert('ExecuteJavaScript works!');","<my URL> ", 0);

but nothing seems to happen when the browser loads .. Am I missing something ? Can someone help me ? Should I do something in my HTML side? (So far I only have a button in my HTML page , no script tag or anything )
ramyakrishnan
Mentor
 
Posts: 62
Joined: Wed Sep 16, 2015 12:21 pm

Re: ExecuteJavaScript() in JCEF

Postby magreenblatt » Tue Sep 22, 2015 11:29 am

What OS and JCEF version are you using? Where are you calling browser.executeJavaScript from?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: ExecuteJavaScript() in JCEF

Postby ramyakrishnan » Tue Sep 22, 2015 11:33 am

Hi ,
I am using Windows 7 , JCEF 3.2~ and I am calling it on my Main.java where I have created a browser instance. Does that help ?
ramyakrishnan
Mentor
 
Posts: 62
Joined: Wed Sep 16, 2015 12:21 pm

Re: ExecuteJavaScript() in JCEF

Postby ramyakrishnan » Tue Sep 22, 2015 11:47 am

To be more precise I created a JPanel using Java Swing and I loaded my CefBrowser instance on top of it .. and now I am trying to call my Javascript from this .java file and trying to execute it.

A small snippet of my code looks as follows :

public class Main{
private final CefClient client;
public Main(CefClient client){
this.client = client;
}
public static void main(String[] args ){
CefBrowser browser = client.createBrowser("http://www.google.com" ,true , true );
< here i wrote some code to create frame and JPanel and added the code to put this browser on my JPanel >
browser.executeJavaScript("alert('ExecuteJavaScript works!');",
browser.getURL(), 0);

...
}

}
Last edited by ramyakrishnan on Tue Sep 22, 2015 12:41 pm, edited 1 time in total.
ramyakrishnan
Mentor
 
Posts: 62
Joined: Wed Sep 16, 2015 12:21 pm

Re: ExecuteJavaScript() in JCEF

Postby magreenblatt » Tue Sep 22, 2015 12:37 pm

You will need to call it after the renderer process has been created. For example, from onLoadEnd.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: ExecuteJavaScript() in JCEF

Postby ramyakrishnan » Tue Sep 22, 2015 12:44 pm

Thankyou ... Could u additionally provide me some example that I can follow? I couldnt understand very clearly what that means.
ramyakrishnan
Mentor
 
Posts: 62
Joined: Wed Sep 16, 2015 12:21 pm

Re: ExecuteJavaScript() in JCEF

Postby magreenblatt » Tue Sep 22, 2015 12:48 pm

Look at the detailed test application included with JCEF. It includes an example.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: ExecuteJavaScript() in JCEF

Postby ramyakrishnan » Tue Sep 22, 2015 2:18 pm

Thank you very much! I got this working :D u made my day!
ramyakrishnan
Mentor
 
Posts: 62
Joined: Wed Sep 16, 2015 12:21 pm


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 151 guests