【问题标题】:calling one function in an .html into another .html [duplicate]将.html中的一个函数调用到另一个.html [重复]
【发布时间】:2014-10-14 06:43:15
【问题描述】:

您好,我想将一个函数从 1 个 .html 文件调用到另一个 .html 文件

Parent.html

<html>
<body>
<script>
function alertFunction() 
{
    alert("I am an alert box!");
}
</script>
<iframe src="childFile.html" width="80%" height="80%"></iframe>
</body>
</html>

Child.html

<button type="button" onClick="alertFunction()">button</button>

因此,当我点击父 .html 页面时,将打开一个带有该框架中按钮的框架......当我单击该按钮时,它应该调用该函数并在 parent.html 文件中显示警报

【问题讨论】:

  • 你应该编写单独的 javascript 文件

标签: javascript html iframe


【解决方案1】:

onClick="parent.alertFunction()"

window.parent 可以完成这项工作。

【讨论】:

  • Uncaught SecurityError: 阻止了来源为“null”的框架访问来源为“null”的框架。协议、域和端口必须匹配。对于 chrome,我得到了这个,但其他浏览器可以正常工作....如何解决它
  • 对不起,我对 Chrome 不太了解。但是,我用谷歌搜索,似乎很多程序员都遇到了同样的问题,他们已经找到了解决方案。请参考stackoverflow.com/questions/17950598/…
  • @taj — 使用本地 HTTP 服务器进行开发,而不是将浏览器直接指向硬盘。
猜你喜欢
  • 1970-01-01
  • 2017-03-07
  • 2014-01-19
  • 1970-01-01
  • 1970-01-01
  • 2013-12-25
  • 2022-01-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多