Sign in to follow this  
Sorginator

Array from js to cef

Recommended Posts

Hey guys,

I tried to pass an array to a function in the cef, but it failed.

Test Code:

// Javascript
let array = ["Test1", "Test2"];
mp.keys.bind(0x59, true, function() {
	browser = mp.browsers.new("package://test/cef/index.html");
	browser.execute('testFunc("' + array + '")');
});

//CEF
function testFunc(testArray) {
    var testDiv = document.createElement("div");
	testDiv.className='tttTt';
	testDiv.id = "testDiv1";
	testDiv.innerText = testArray[0];
}

 

I've also tried the following code:

// Javascript
let array = ["Test1", "Test2"];
mp.keys.bind(0x59, true, function() {
	browser = mp.browsers.new("package://test/cef/index.html");
    let jsonStrng = JSON.stringify(array);
	browser.execute('testFunc("' + jsonStrng + '")');
});

//CEF
function testFunc(testArrayJSON) {
  	let testArray = JSON.parse(testArrayJSON);
    var testDiv = document.createElement("div");
	testDiv.className='tttTt';
	testDiv.id = "testDiv1";
	testDiv.innerText = testArray[0];
}

 

Can you tell me what I did wrong or/and how to pass arrays from Javascript to the CEF?

Share this post


Link to post
Share on other sites

Try passing your JSON string in the function like this 

browser.execute(`testFunc('${jsonString}');`);

 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.