Test iframe rendering

This commit is contained in:
titaneric 2021-03-20 16:37:50 +08:00
parent e6568a70eb
commit e04b254b48
1 changed files with 49 additions and 20 deletions

View File

@ -124,17 +124,46 @@ function playground_text(playground) {
result_block.innerText = "Running...";
fetch_with_timeout("https://play.rust-lang.org/evaluate.json", {
headers: {
'Content-Type': "application/json",
},
method: 'POST',
mode: 'cors',
body: JSON.stringify(params)
// fetch_with_timeout("https://play.rust-lang.org/evaluate.json", {
// headers: {
// 'Content-Type': "application/json",
// },
// method: 'POST',
// mode: 'cors',
// body: JSON.stringify(params)
// })
new Promise((resolve, reject) => {
setTimeout(() => {
resolve("foo");
}, 200)
})
// .then(response => response.json())
// .then(response => result_block.innerText = response.result)
// .then(response => result_block.innerHTML = "<div style=\"height: 300px;background-color: red;\"></div>")
// .then(response => result_block.innerHTML = " <div id=\"button_click\"></div><script type=\"module\" src=\"wasm-test.js\"></script>")
.then(response => {
result_block.innerText = "";
var iframe = result_block.appendChild(document.createElement('iframe')),
doc = iframe.contentWindow.document,
options = {
objid: 152,
key: 316541321
},
//src = "host/widget.js",
uri = encodeURIComponent(JSON.stringify(options));
doc.someVar = "Hello World!";
iframe.id = "iframewidget";
iframe.width = result_block.width;
iframe.height = result_block.height;
var html = '<body onload="var d=document;' +
'var script=d.createElement(\'script\');script.type=\'module\';script.src=\'wasm-test.js\';' +
'd.getElementsByTagName(\'head\')[0].appendChild(script);"><div id="button_click"></div></body>';
doc.open().write(html);
doc.close();
})
.then(response => response.json())
.then(response => result_block.innerText = response.result)
.catch(error => result_block.innerText = "Playground Communication: " + error.message);
}
// Syntax highlighting Configuration