1

I am using v8 and i faced next problem - i have an application which running a javascript file ( i simply read it into a string and than execute with

Local<String> source = String::New(javascript); //javascript is string with js file
Local<Script> script = Script::Compile(source);
Local<Value> result = script->Run(); 

how can I send a string variable into this file?

2
  • where does the string need to be inserted? at the beginning, at the end, somewhere in the middle? Commented May 12, 2011 at 15:33
  • it has to be inserted instead a js string ar the beginning of the script. but I already solved this problem by putting var str = " " into a js and replacing it with value which have to setted Commented May 16, 2011 at 15:58

1 Answer 1

1

Put a placeholder in the script source, like STRING_HERE. Then, before creating the source object, find that placeholder in the string and replace it with the string value you want.

Sign up to request clarification or add additional context in comments.

1 Comment

so I should put mplaceholder into my JS file like this ` function Process(){ var theElement = document.getElementById("myPlaceholder"); ... } ` and then after reading this file into a C++ string just simply replace it with the variable which I want to send? that's it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.