Press button in iFrame

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
dpankowski
Profound User
Posts: 35
Joined: Fri Jul 12, 2013 12:58 pm
First Name: Dan
Last Name: Pankowski
Company Name: Sinclair Services
Phone: 8015242956
Address 1: 550 E South Temple
City: Salt Lake City
State / Province: Utah
Zip / Postal Code: 84102
Country: United States
Contact:

Press button in iFrame

Post by dpankowski »

I am running a rich display file program in an iFrame, and I need to press a button or even change an element value from the parent ui. I searched the forum and didn't quite find what I needed.
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: Press button in iFrame

Post by David »

When running in a frame, the JavaScript object 'parent' contains a reference to 'window' of the containing page. All globals are actually properties of 'window'. So, from the iframe you can run code like this to do things in the parent page:

Code: Select all


parent.pui.click("buttonId");

I think this sort of thing can be subject to 'same origin' policy, so likely will not work in some/all browsers unless the page in the iframe is on the same web server.
dpankowski
Profound User
Posts: 35
Joined: Fri Jul 12, 2013 12:58 pm
First Name: Dan
Last Name: Pankowski
Company Name: Sinclair Services
Phone: 8015242956
Address 1: 550 E South Temple
City: Salt Lake City
State / Province: Utah
Zip / Postal Code: 84102
Country: United States
Contact:

Re: Press button in iFrame

Post by dpankowski »

Sorry I don't I was being clear.

I want to press a button of the program running IN the iFrame not press the parent's button from the iFrame.

Does this make sense?

Thanks
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: Press button in iFrame

Post by David »

Oops! Seems that I got it backwards here. The question I answered is a common one -- I was on auto-pilot, sorry.

There are multiple ways to get a reference to the iframe from the parent page? I assume you are familiar with those. One way is using the id, of course. Once you have a reference to the iframe, it has properties called 'contentDocument' and 'contentWindow' which are 'document' and 'window' in the iframe page. As described before, all globals are actually properties of 'window', so you can run code like this in the parent page to click a button or change a value in the iframe:

Code: Select all


var iframeWin = document.getElementById("iframeId").contentWindow;

// Click a button
iframeWin.pui.click("buttonId");

// Change a widget value.
iframeWin.pui.set("widgetId", "new value");

Same origin policy will apply here, too, I think.
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: Press button in iFrame

Post by David »

Ha ha -- you were being clear enough. I was being a zombie. :-)
dpankowski
Profound User
Posts: 35
Joined: Fri Jul 12, 2013 12:58 pm
First Name: Dan
Last Name: Pankowski
Company Name: Sinclair Services
Phone: 8015242956
Address 1: 550 E South Temple
City: Salt Lake City
State / Province: Utah
Zip / Postal Code: 84102
Country: United States
Contact:

Re: Press button in iFrame

Post by dpankowski »

thanks it's all good.
It's been a long day for me too ;)
I'll give this a try.
dpankowski
Profound User
Posts: 35
Joined: Fri Jul 12, 2013 12:58 pm
First Name: Dan
Last Name: Pankowski
Company Name: Sinclair Services
Phone: 8015242956
Address 1: 550 E South Temple
City: Salt Lake City
State / Province: Utah
Zip / Postal Code: 84102
Country: United States
Contact:

Re: Press button in iFrame

Post by dpankowski »

Hi,

I tried this, and I'm getting a js error "Object#<Object> has no method 'click'" I'm running in preview mode, if that makes a difference.

Code: Select all

var iframeWin = document.getElementById("iFrame1");
iframeWin.pui.click("exitButton");
It's a styled button and I've check the Id, and they're both running on the same server.

Thanks
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Press button in iFrame

Post by Scott Klement »

Hmmm... is this a Profound UI Rich Display running inside another Profound UI Rich Display's iframe? If so, you'll need to make the code look like this:

Code: Select all

var iframeWin = document.getElementById("iFrame1");
iFrameWin.firstChild.contentWindow.pui.click("exitButton");
Or using the Profound-specific API:

Code: Select all

var iframeWin = getObj("iFrame1");
iFrameWin.firstChild.contentWindow.pui.click("exitButton");
Or if you prefer the "one-liner" code, you could do this:

Code: Select all

getObj("iFrame1").firstChild.contentWindow.pui.click("exitButton");
Good Luck!
dpankowski
Profound User
Posts: 35
Joined: Fri Jul 12, 2013 12:58 pm
First Name: Dan
Last Name: Pankowski
Company Name: Sinclair Services
Phone: 8015242956
Address 1: 550 E South Temple
City: Salt Lake City
State / Province: Utah
Zip / Postal Code: 84102
Country: United States
Contact:

Re: Press button in iFrame

Post by dpankowski »

Thanks Scott,

That worked!
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: Press button in iFrame

Post by David »

Sorry for the confusion here. While I mentioned 'contentWindow', I goofed and my original sample code was not correct.

I updated it for future reference.
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests