调用函数并将参数传递给父级的iframe

时间:2012-11-14 04:03:20

标签: javascript iframe

我正在尝试调用函数并将参数传递给父级的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');
}

它会起作用。

我该怎么做才能解决这个问题?谢谢你的帮助!!!

1 个答案:

答案 0 :(得分:-1)

name是JS中的保留关键字,因此您不能将其用于变量/参数。只需为您的论点和拨打detect时使用不同的名称。你的代码看起来不错。

相关问题