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!!!
nameis 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 calldetect. Your code looks otherwise fine.