Page 1 of 1

How can I access a variable from an iFrame's page in PUI?

Posted: Fri May 31, 2013 3:36 pm
by kevinh
I have a PUI page that is defined as a window that has an iFrame container that runs a RPGsp page via the URL executed by the iFrame.
There is a variable on the RPGsp page (in the iFrame) that is set to True once a change has been made in a text area on the page.

Is there a way for the PUI page to access that variable so that the PUI page (the main window) can know if changes have been made on the RPGsp page (in the iFrame)?

Also, currently the user must submit the RPGsp page in the iframe to save their changes and then click Close on the PUI window/page to close the window.

My first goal is to be able to warn the user if they try to close the PUI window after making changes on the RPGsp page in the iFrame but have not submitted the changes via the RPGsp page's Submit button.
My second goal is to find a way to automatically close the PUI window once a successful Submit has taken place in the iFrame, but I'm not sure that's even possible.

I've researched this and found some html examples where variables of an iFrame can be accessed using something like

Code: Select all

window.iFrameName.varName
where iFrameName is the iFrame's Name property and the varName is the variable within the iFrame.
I don't see the Name property in the PUI designer for an iFrame.

Is there a way to do this in PUI?

Re: How can I access a variable from an iFrame's page in PUI?

Posted: Fri May 31, 2013 6:32 pm
by David
Try this:

Code: Select all


// Get reference to 'window' in iframe.
// The iframe widget is a <div> element which contains an <iframe>
// The 'contentWindow' property on the iframe is the contained page's 'window' object.

// Global variables on page are properties of 'window'. 
var win = getObj("IFrameWidgetId").firstChild.contentWindow;

alert(win.varName);

Accessing stuff across iframes will only work reliably if the PUI and RPGsp pages are served from the same http server, or if the browser thinks they are through reverse proxy setup.

If it sees them on 2 separate http servers, you'll get a security error when trying to access things in the iframe.

Re: How can I access a variable from an iFrame's page in PUI?

Posted: Sun Jun 02, 2013 4:33 pm
by kevinh
Perfect. Exactly what I needed.
...and when coupled with this post http://www.profoundlogic.com/forums/php ... =53&t=1420 I am able to keep a user from accidentally closing the PUI window without submitting the RPGsp page called in the iFrame.
Thanks!!