我正在尝试调用一个函数并将参数从父级传递给 iframe javascript 函数。
我有
document.getElementById('iframeD').contentWindow.detect(name);
在我的父 JavaScript 中
在我的 iframe 中..如果我有
function detect(name){
console.log(name);
}
它会给我
Uncaught SyntaxError: Unexpected token name
但是,如果我只调用不带参数的函数
document.getElementById('iframeD').contentWindow.detect();
并使我的 iframe 功能
function detect(){
console.log('I want to pass the pare');
}
它会起作用的。
我可以做什么来解决这个问题?感谢您的帮助!!!
最佳答案
name
是 JS 中的保留关键字,因此不能将其用于变量/参数。只需在参数和调用 detect
时使用不同的名称即可。您的代码看起来不错。
关于javascript - 调用函数并将参数从父级传递给 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13372841/