Jump to content

Recommended Posts

Posted

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?

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...