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

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
kevinh
Profound User
Posts: 43
Joined: Tue May 19, 2009 4:31 pm
First Name: Kevin
Last Name: Hunter
Company Name: Integrated Corporate Solutions
Phone: 2567608239
Address 1: 501 S Wood Ave
City: Florence
State / Province: Alabama
Zip / Postal Code: 35630
Country: United States
Location: Florence Alabama
Contact:

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

Post 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?
User avatar
David
Profound Logic Staff Member
Posts: 690
Joined: Fri Jan 04, 2008 12:11 pm
First Name: David
Last Name: Russo
Company Name: Profound Logic Software
Contact:

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

Post 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.
kevinh
Profound User
Posts: 43
Joined: Tue May 19, 2009 4:31 pm
First Name: Kevin
Last Name: Hunter
Company Name: Integrated Corporate Solutions
Phone: 2567608239
Address 1: 501 S Wood Ave
City: Florence
State / Province: Alabama
Zip / Postal Code: 35630
Country: United States
Location: Florence Alabama
Contact:

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

Post 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!!
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests