Forum Moderators: open

Message Too Old, No Replies

Getting Parent Variable in iFrame

         

inveni0

4:01 pm on Oct 28, 2009 (gmt 0)

10+ Year Member



I'm currently developing an application on the iPhone that uses the <canvas> tag. Unfortunately, the toDataURL method does not appear to be compatible with webkit. As a temporary work-around, I'm attempting to process the toDataURL function via the web by using an iFrame in my iPhone app (because toDataURL works fine over the web). I can not, however, seem to get the parent variable in my iFrame so that I can process it. Here's a sample of code:

PARENT FRAME:

<script>
var strDataURI;
oCanvas = document.gelElementById('canvas');
document.getElementById('iframe').src = "http://myspecialpage.com/todataurl.php";
</script>

IFRAME:

<script>
alert("page loaded");
alert(parent.oCanvas);
parent.strDataURI = parent.oCanvas.toDataURL();
alert("finished");
</script>

Now, this is how I've always assumed it to be done. But for some reason, the iFrame doesn't get the parent variable 'oCanvas'. I've set up a few debugging alerts in the in the iFrame pane, and the second one returns "undefined". The script ceases execution after that line.

So, my question is, what is the real way to get a parent variable in an iFrame--and then to change it?

Thanks!

daveVk

12:25 am on Oct 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the iframe is sourced from a different domain than parent frame, this is a security issue.

inveni0

2:48 am on Oct 29, 2009 (gmt 0)

10+ Year Member



Is it an issue on sending objects within variables only? Because I have had success on transferring variables that contain only strings in the past. The problem is that I need to send out the canvas data.

daveVk

3:06 am on Oct 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Same_origin_policy_for_JavaScript [developer.mozilla.org...] IF this applies there is not much you can see or do within parent, there are some exceptions that allow frame breakers to work and odd cross domain tricks.

inveni0

3:29 am on Oct 29, 2009 (gmt 0)

10+ Year Member



How could you check to see if this was the issue? Like I said, I have another iPhone app that does this without issue... The only difference is that it's not passing an object.

daveVk

3:51 am on Oct 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



document.getElementById('iframe').src = "http://myspecialpage.com/todataurl.php";

if the parent frame also comes from there, this is not the issue.

alert(parent.location.href) may be suitable test.

inveni0

6:07 am on Oct 29, 2009 (gmt 0)

10+ Year Member



Like I said, the parent frame is runningly locally on the iPhone. So there's no way it's from the same domain. Is there no way to force error reports to the browser?

My next step, I suppose, will be verifying that the issue resides with the object only by attempting to pass a variable of type String