Online since 2002. Over 3300 puzzles, 2600 worldwide members, and 270,000 messages.

TwistyPuzzles.com Forum

It is currently Mon Apr 21, 2014 2:32 am

All times are UTC - 5 hours



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Help: Javascript function vs iFrame permission
PostPosted: Sat Feb 23, 2013 12:21 pm 
Offline
User avatar

Joined: Wed Jan 28, 2009 7:55 pm
Location: Montana
I'm having a problem with JavaScript- as the title suggests. Here I have some parent code:

Code:
<html>
   <head>
      <script type="text/javascript">
function foo() {
   alert ("Reached foo()!");
}
function bar(parameter){
   alert ("Reached bar(" + parameter + ")");
}
      </script>
   </head>
   <body>
      <div>Some content.</div>
      <iframe src="child.html"></iframe>
   </body>
</html>


And the child:

Code:
<html>
   ...
   <body>
      <input type="button" onclick="parent.foo()">
      <input type="button" onclick="parent.bar(1)">
   </body>
</html>


The problem I'm having is that foo() works fine, while bar(p) does not. It says I have unsafe access/don't have permission. The error occurs only if I pass a parameter. All the help online says the problem is that they need to be in the same domain, but they already are. I've tried action listeners rather than onclick with no success, and I've tried moving child.html into a subdirectory of the parent's location and vice versa. I've tried other kinds of elements besides inputs as well.


Anyone have ideas?

_________________
Andreas Nortmann wrote:
Things like this are illegal.
If not I will pass an appropriate law.


Top
 Profile  
 
 Post subject: Re: Help: Javascript function vs iFrame permission
PostPosted: Sat Feb 23, 2013 1:24 pm 
Online
User avatar

Joined: Mon Jun 18, 2012 10:56 am
Location: The Netherlands
Ok, not a CLUE what I am saying here. I showed this to a friend and he said:


I suspect that the vars have to be parsed as "./parent.bar(1)">


Again.. he could be speaking Chinese.. at least I know he is not swearing here LOL!


Top
 Profile  
 
 Post subject: Re: Help: Javascript function vs iFrame permission
PostPosted: Sat Feb 23, 2013 1:26 pm 
Offline
User avatar

Joined: Thu Dec 31, 2009 8:54 pm
Location: Bay Area, California
You're probably using Chrome which has some stricter security checks.

Have you seen http://stackoverflow.com/questions/2161388/iframe-function-calling-from-iframe-to-parent-page-javascript-function

Setting the document.domain DOM element in both pages may do the trick.

_________________
Prior to using my real name I posted under the account named bmenrigh.


Top
 Profile  
 
 Post subject: Re: Help: Javascript function vs iFrame permission
PostPosted: Sat Feb 23, 2013 1:57 pm 
Offline
User avatar

Joined: Wed Jan 28, 2009 7:55 pm
Location: Montana
Yes, I used that page for assistance, and it does work when it's set up like on that page, but once I try to pass a parameter, all hell breaks loose. I'll take a look at the DOM and see if that fixes it.


Also, yes, I am in Chrome.


Kattenvriendin wrote:
Ok, not a CLUE what I am saying here. I showed this to a friend and he said:
I suspect that the vars have to be parsed as "./parent.bar(1)">

This would be the correct answer if I was trying to access a file, but I'm look for a function.

_________________
Andreas Nortmann wrote:
Things like this are illegal.
If not I will pass an appropriate law.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Forum powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group