I am trying to call a function and pass a parameter to a iframe javascript function from the parent.
I have
document.getElementById('iframeD').contentWindow.detect(name);
in my parent javascript
in my iframe..if I have
function detect(name){
console.log(name);
}
it will gives me
Uncaught SyntaxError: Unexpected token name
However, if I only call the function without parameter
document.getElementById('iframeD').contentWindow.detect();
and make my iframe function
function detect(){
console.log('I want to pass the pare');
}
it will works.
What can I do to solve this? Thanks for the help!!!
name
is a reserved keyword in JS, so you can't use it for variables/arguments. Just use a different name both for your argument and when you call detect
. Your code looks otherwise fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.