Press button in iFrame
-
- 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
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.
- 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
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.
Code: Select all
parent.pui.click("buttonId");
-
- 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
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
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
- 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
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:
Same origin policy will apply here, too, I think.
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");
- 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
Ha ha -- you were being clear enough. I was being a zombie. :-)
-
- 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
thanks it's all good.
It's been a long day for me too ;)
I'll give this a try.
It's been a long day for me too ;)
I'll give this a try.
-
- 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
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.
It's a styled button and I've check the Id, and they're both running on the same server.
Thanks
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");
Thanks
-
- 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
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:
Or using the Profound-specific API:
Or if you prefer the "one-liner" code, you could do this:
Good Luck!
Code: Select all
var iframeWin = document.getElementById("iFrame1");
iFrameWin.firstChild.contentWindow.pui.click("exitButton");
Code: Select all
var iframeWin = getObj("iFrame1");
iFrameWin.firstChild.contentWindow.pui.click("exitButton");
Code: Select all
getObj("iFrame1").firstChild.contentWindow.pui.click("exitButton");
-
- 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
Thanks Scott,
That worked!
That worked!
- 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
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.
I updated it for future reference.
Who is online
Users browsing this forum: No registered users and 0 guests