目前我有两个HTML文件。一个名为index.html,另一个名为editor.html在脚本标记内的不同HTML文件中运行JavaScript函数
Inside index.html我有一个iframe的editor.html上面这个iframe也是我制作的通知系统。要运行它使用我创建了一个功能的通知,可以使用像这样:当我把它在index.html内
Notification("msg");
此功能的伟大工程,因为函数修改的index.html的HTML代码(通过.innerHTML)。一个问题显示出来,当我试图从editor.html
即使有editor.html加入到这样的index.html在index.html的顶部叫它:
<script src="editor.html"></script>
我写这在editor.html:
<script src="index.html"></script>
当我尝试并运行editor.html通知功能有一个错误,因为该功能是index.html的内部和修改的index.html,不编辑器html的。
请记住,在每个index.html和editor.html中,javascript都位于标记中,因为文件中存在其他html。谢谢,如果您需要进一步确认,请提问。
一个页面不能直接在另一个页面上运行代码。他们只能使用['Window.postMessage()'](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage)进行通信和传输数据。从iframe内部,这将是'window.parent.postMessage()',并从iframe外的document.querySelector('iframe')。contentWindow.postMessage()'。您还需要在任何接收页面上附加“消息”事件的事件侦听器。 – Siguza
你可以举个例子使用独立的index.html和editor.html吗?一种传递函数和参数的方法? –