vy.pham
vy.pham

Reputation: 611

How to executeJavascript and return value on phonegap?

On electronjs i can use executeJavascript on another site and return value like bellow, could i do that on phonegap?

mainWindow.webcontent.executeJavasciprt(someScript)

i found it, using window.open

var ref = window.open('your_url_hear', '_blank');
ref.addEventListener('loadstop', async function() {//wait for url stop loading
    ref.executeScript({code: `document.write('123'); function returnvalue(){
    var value = 123;
    return value
};returnvalue()`},function(value){
    //callback return value of the last row of code, we can use ref.executeScript({file:'patch_to_js_file'}) 
    console.log(value)
});

Upvotes: 0

Views: 281

Answers (1)

Muhammad Kamran
Muhammad Kamran

Reputation: 109

you have to run your code as a string type try below code this works fine

win.webContents.executeJavaScript(`alert(${varible_value});`);

Upvotes: 1

Related Questions