我有一个故事情节文件,它在我的索引文件的新窗口中使用onclick事件打开。我有以下代码。
<div class="ease col-6 filterDiv interactives">
<img class="display-b img-fluid" src="assets/images/digital-wellness-thumbnail.jpg" alt="alt">
<a onclick="window.open('assets/storyline/digital-wellness/story.html', '_blank', 'location=yes,width=1024,height=768,scrollbars=yes,status=yes')">
<div class="overlay">
<i class="fa fa-plus-circle fa-lg text-overlay"></i>
</div>
</a>
</div>
这是打开一个故事情节文件,(在说“只编辑story.html文件”之前,我已经尝试过了,它不起作用),我想看看有没有办法在story.html文件在新窗口中打开后附加一些html。这个是可能的吗?
发布于 2018-06-21 03:09:12
您可以创建新窗口的句柄,并通过向其发送带有postMessage() API的消息来修改其HTML。新窗口的页面必须知道如何接受消息以及如何处理它:
主页:
document.getElementById('my-link').addEventListener('click', function (event) {
const newWindow = window.open('http://example.com/new-window.html');
newWindow.postMessage('<div>Some HTML</div>', 'http://example.com/index.html');
});
新建窗口页面:
window.addEventListener('message', receiveMessage, false);
function receiveMessage(event) {
if (event.origin !== 'http://example.com/index.html') return;
// Do something with event.message, which contains the HTML
}
请通读整个文档,因为它为如何启动和运行提供了很好的示例。
为内联编辑:
<a onclick="javascript:var newWindow = window.open('assets/storyline/digital-wellness/
story.html','_blank', 'location=yes,width=1024,height=768,scrollbars=yes,status=yes');
newWindow.postMessage('<div>Some HTML</div>', '/index.html');">
<div class="overlay">
<i class="fa fa-plus-circle fa-lg text-overlay"></i>
</div>
</a>
https://stackoverflow.com/questions/50954411
复制相似问题