Advertisement

Calling a js function in parent document from an iframe:

Moderators: Calcifer, slothy

Calling a js function in parent document from an iframe:

Postby obiwon » Thu Sep 21, 2006 4:11 am

I spent the last three days searching the web for a solution to a js problem i was encountering and I was so frustrated that I could not find the answer that I am posting it so someone else in similar situation may benefit..

I was getting this error: Error:
Permission denied to get property Window.someFunction();

I was trying to call a function like parent.someFunction(); from a document in an iframe whereas the parent. is the top frame/document that establishes the iframe.

The problem had nothing to do with the javascript, but in the way the src="" attribute of the iframe tag! (shocker I know..) I had an absolute URL (which was on the same domain so I did not think it would be an issue at all) that apparently triggered both firefox and ie security messages.

As soon as I switched the src="" from http://domain.com/script.php to script.php (without the http://domain.com which I think made the browsers believe I was attempting to call a script from another server) everything works fine; I am now able to work back and forth from iframe js to parent js without problem.

So the moral of the story is that if you have Googled all you can and your syntax is correct [ parent.someFunction() ] and you are getting errors that say permission denied, check the src="" of the iframe tag in your parent document before pulling your hair out. You may just have an absolute URL value.

PS- need some hair?

Obiwon
obiwon
 
Posts: 10
Joined: Tue Aug 22, 2006 2:59 am

Return to Javascript

Who is online

Users browsing this forum: No registered users and 6 guests

cron