Test iframe rendering
This commit is contained in:
parent
e6568a70eb
commit
e04b254b48
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue