Page 1 of 1
Press button in iFrame
Posted: Wed Feb 26, 2014 6:40 pm
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.
Re: Press button in iFrame
Posted: Wed Feb 26, 2014 6:54 pm
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:
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.
Re: Press button in iFrame
Posted: Wed Feb 26, 2014 7:05 pm
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
Re: Press button in iFrame
Posted: Wed Feb 26, 2014 7:05 pm
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.
Re: Press button in iFrame
Posted: Wed Feb 26, 2014 7:06 pm
by David
Ha ha -- you were being clear enough. I was being a zombie. :-)
Re: Press button in iFrame
Posted: Wed Feb 26, 2014 7:10 pm
by dpankowski
thanks it's all good.
It's been a long day for me too ;)
I'll give this a try.
Re: Press button in iFrame
Posted: Tue Mar 04, 2014 7:41 pm
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
Re: Press button in iFrame
Posted: Wed Mar 05, 2014 2:06 am
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!
Re: Press button in iFrame
Posted: Wed Mar 05, 2014 4:04 pm
by dpankowski
Thanks Scott,
That worked!
Re: Press button in iFrame
Posted: Mon Mar 17, 2014 10:11 am
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.