Does vscode webview supports javascript?
Does vscode webview supports javascript?
I want to display the configuration (a json file) of my extension in a webview then user can change some configuration then save back to json file. I can read the html file and json in my extension, then use interpolation to generate the html string. But it seems that the javascript in html string didn't work. I tried to test with a simple html with a simple javascript script:
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p>My First Paragraph</p>
<p id="demo">demo</p>
<script>
document.getElementById("demo").innerHTML = "succesfull";
</script>
</body>
</html>
In my extension.ts
:
extension.ts
vscode.commands.registerCommand('extension.sayHello', () => {
const editor = vscode.window.activeTextEditor;
if (!editor || !editor.viewColumn) { return; }
let column = editor.viewColumn ? editor.viewColumn + 1 : 1;
const panel = vscode.window.createWebviewPanel(
'id', "Title", column, {}
);
let htmlPath = join(__dirname, '../testjs.html');
vscode.workspace.openTextDocument(htmlPath).then((textDoc) => {
const txt = textDoc.getText();
panel.webview.html = txt;
}, (err) => {
vscode.window.showErrorMessage("Cannot open: " + htmlPath);
});
});
Is this right: vscode webview did not support javascript? Can you give me some hints in this case to display the configuration and edit it? Thank you very much!
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.