FoxPro Programming
Re: How to address iFrame in Web-Browser Control from VFP
Gravatar is a globally recognized avatar based on your email address. Re: How to address iFrame in Web-Browser Control from VFP
  Steve
  Rick Strahl
  Jan 27, 2016 @ 12:01pm
Hi All,
I have the name of the iFrame. However, I cannot seem to figure out how to get a reference to the iFrame from within VFP. I am displaying the web page using the Browser Control on a standard VFP Form. I can access the Document Object. I am capturing the iFrame name in a variable called lciFrame.
I see where Rick says to use window.frames[framename], but isn't that JScript?

1) Is it possible to access the content of an iFrame? Or, is this considered XSS and now allowed?
2) What is the syntax???
I can get a reference to the parent frame using: oFrame = o.Document.Frames(lcFrame)
What's the next step to get the InnerHTML for the iFrame?

TIA,
Steve


I think selecting the iFrame doesn't give you the actual frame/window instance. You need to use window.frames[framename] to find the actual frame instance. From there you should be able to say loFrame.document and go on accessing the frame.

Note depending on your security settings you may not be able to script into a frame as it's a potential security issue (cross site scripting).

+++ Rick ---

Hi all,

Using the web-browser control I can get the HTML code from a URL. What do I do though, when I need to get the .innerHTML for one of a series of iFrames?

What might be the syntax to make that work

* locate all iFrames - using TagName
FOR EACH loTag IN o.DOCUMENT.ALL
IF UPPER(loTag.Tagname) == "IFRAME"

* how do I address the InnerHTML of the iFrame itself?

lcResult = loTag.Tagname && here I get "IFRAME", the name


*produce errors
* lcResult = loTag.inhherhtml
* lcResult = lotag.parent.innerhtml
* lcResult = lotag.body.innerhtml

* lcResult = lotag.document.body.innerhtml
* works, but its not the iFrame even though I'm on that particular iFrame element

* what could be the appropriate syntax here to catch the iFrame?
lcResult = lotag.document.body.innerhtml

ENDIF
ENDFOR

Another approach, since I can even access the url of the iFrames could be something like

lchtml= "http://s36.wurzelimperium.de/verkauf.php?kunde=19059542&kundemap=i2.innerhtml" target="top" >http://s36.wurzelimperium.de/verkauf.php?kunde=19059542&kundemap=i2.innerhtml


* or

o.document.frames(1).innerHTML && ? - if I know from the url that it's frame 2 (i1) that I'm dealing with?

Again: what would be the correct syntax for an approach along these lines? Or what would be alternatives?

All this seems to be a question of "how", since I can simply - by right-clicking on the browser - do a save-as (source code) and get the HTML that I'm looking for, but I don't manage to do this under program control.

TIA,

Teddy




Gravatar is a globally recognized avatar based on your email address. Re: How to address iFrame in Web-Browser Control from VFP
  Rick Strahl
  Steve
  Jan 27, 2016 @ 04:42pm
Regardless of whether its via COM or JavaScript you have to traverse the hierarchy. I believe you can walk the frames using the windows' parent to get the master framelist, then select the fram and the window from there. This should workin the Web Browser control or IE automation.

+++ Rick ---



Hi All,
I have the name of the iFrame. However, I cannot seem to figure out how to get a reference to the iFrame from within VFP. I am displaying the web page using the Browser Control on a standard VFP Form. I can access the Document Object. I am capturing the iFrame name in a variable called lciFrame.
I see where Rick says to use window.frames[framename], but isn't that JScript?

1) Is it possible to access the content of an iFrame? Or, is this considered XSS and now allowed?
2) What is the syntax???
I can get a reference to the parent frame using: oFrame = o.Document.Frames(lcFrame)
What's the next step to get the InnerHTML for the iFrame?

TIA,
Steve


I think selecting the iFrame doesn't give you the actual frame/window instance. You need to use window.frames[framename] to find the actual frame instance. From there you should be able to say loFrame.document and go on accessing the frame.

Note depending on your security settings you may not be able to script into a frame as it's a potential security issue (cross site scripting).

+++ Rick ---

Hi all,

Using the web-browser control I can get the HTML code from a URL. What do I do though, when I need to get the .innerHTML for one of a series of iFrames?

What might be the syntax to make that work

* locate all iFrames - using TagName
FOR EACH loTag IN o.DOCUMENT.ALL
IF UPPER(loTag.Tagname) == "IFRAME"

* how do I address the InnerHTML of the iFrame itself?

lcResult = loTag.Tagname && here I get "IFRAME", the name


*produce errors
* lcResult = loTag.inhherhtml
* lcResult = lotag.parent.innerhtml
* lcResult = lotag.body.innerhtml

* lcResult = lotag.document.body.innerhtml
* works, but its not the iFrame even though I'm on that particular iFrame element

* what could be the appropriate syntax here to catch the iFrame?
lcResult = lotag.document.body.innerhtml

ENDIF
ENDFOR

Another approach, since I can even access the url of the iFrames could be something like

lchtml= "http://s36.wurzelimperium.de/verkauf.php?kunde=19059542&kundemap=i2.innerhtml" target="top" >http://s36.wurzelimperium.de/verkauf.php?kunde=19059542&kundemap=i2.innerhtml


* or

o.document.frames(1).innerHTML && ? - if I know from the url that it's frame 2 (i1) that I'm dealing with?

Again: what would be the correct syntax for an approach along these lines? Or what would be alternatives?

All this seems to be a question of "how", since I can simply - by right-clicking on the browser - do a save-as (source code) and get the HTML that I'm looking for, but I don't manage to do this under program control.

TIA,

Teddy







Rick Strahl
West Wind Technologies

Making waves on the Web
from Maui

Gravatar is a globally recognized avatar based on your email address. Re: How to address iFrame in Web-Browser Control from VFP
  Steve
  Rick Strahl
  Jan 28, 2016 @ 11:50am
Well, after a lot of trial and error, digging, head scratching, etc.... I finally got it to work. What I needed was about 4 levels down. It took me a while to determine that I was dealing with iFrames within iFrames, and how to access those objects. In a nutshell, here is what worked. I did not use shortened object references to help with keeping it all straight.

First, had to check the main page and capture the Level 1 Frame Name, along with a Random Number that gets assigned per session. This gave me:
mainWindow_[RandomName] and is assigned to local variable lcFrame.

Next, I get an object reference to the top level frame: oFrame = ThisForm.oBrowser.Document.Frames(lcFrame)
Next, I get an object reference to the next level frame: oiFrame = oFrame.Document.Frames(lciFrame) &&lciFrame = iframeMgList_[RandomName]
Next, I get an object reference to the next level frame: oiFramePick1 = oiFrame.Document.Frames("iframeSavePick_" + lcRandomName)
Next, I get an object reference to the next level frame: oiFramePick2 = oiFramePick1.Document.Frames("iframePickList_" + lcRandomName)

Once I have oiFramePick2, I can extract the InnerHTML and get to the data I need.
Hopefully this will help someone when the time comes.

Thanks Rick, and to all,
Steve


Regardless of whether its via COM or JavaScript you have to traverse the hierarchy. I believe you can walk the frames using the windows' parent to get the master framelist, then select the fram and the window from there. This should workin the Web Browser control or IE automation.

+++ Rick ---



Hi All,
I have the name of the iFrame. However, I cannot seem to figure out how to get a reference to the iFrame from within VFP. I am displaying the web page using the Browser Control on a standard VFP Form. I can access the Document Object. I am capturing the iFrame name in a variable called lciFrame.
I see where Rick says to use window.frames[framename], but isn't that JScript?

1) Is it possible to access the content of an iFrame? Or, is this considered XSS and now allowed?
2) What is the syntax???
I can get a reference to the parent frame using: oFrame = o.Document.Frames(lcFrame)
What's the next step to get the InnerHTML for the iFrame?

TIA,
Steve


I think selecting the iFrame doesn't give you the actual frame/window instance. You need to use window.frames[framename] to find the actual frame instance. From there you should be able to say loFrame.document and go on accessing the frame.

Note depending on your security settings you may not be able to script into a frame as it's a potential security issue (cross site scripting).

+++ Rick ---

Hi all,

Using the web-browser control I can get the HTML code from a URL. What do I do though, when I need to get the .innerHTML for one of a series of iFrames?

What might be the syntax to make that work

* locate all iFrames - using TagName
FOR EACH loTag IN o.DOCUMENT.ALL
IF UPPER(loTag.Tagname) == "IFRAME"

* how do I address the InnerHTML of the iFrame itself?

lcResult = loTag.Tagname && here I get "IFRAME", the name


*produce errors
* lcResult = loTag.inhherhtml
* lcResult = lotag.parent.innerhtml
* lcResult = lotag.body.innerhtml

* lcResult = lotag.document.body.innerhtml
* works, but its not the iFrame even though I'm on that particular iFrame element

* what could be the appropriate syntax here to catch the iFrame?
lcResult = lotag.document.body.innerhtml

ENDIF
ENDFOR

Another approach, since I can even access the url of the iFrames could be something like

lchtml= "http://s36.wurzelimperium.de/verkauf.php?kunde=19059542&kundemap=i2.innerhtml" target="top" >http://s36.wurzelimperium.de/verkauf.php?kunde=19059542&kundemap=i2.innerhtml


* or

o.document.frames(1).innerHTML && ? - if I know from the url that it's frame 2 (i1) that I'm dealing with?

Again: what would be the correct syntax for an approach along these lines? Or what would be alternatives?

All this seems to be a question of "how", since I can simply - by right-clicking on the browser - do a save-as (source code) and get the HTML that I'm looking for, but I don't manage to do this under program control.

TIA,

Teddy







Gravatar is a globally recognized avatar based on your email address. Re: How to address iFrame in Web-Browser Control from VFP
  Rick Strahl
  Steve
  Jan 28, 2016 @ 12:16pm
FWIW you should be able to get all the frames from the top level document. No need to dig into the individual windows to get the frames collection again. Unless you are nesting frames within frames (I really hope that's not the case - frames are bad enough as it is) the top level frames collection has access to all frames.

+++ Rick ---



Well, after a lot of trial and error, digging, head scratching, etc.... I finally got it to work. What I needed was about 4 levels down. It took me a while to determine that I was dealing with iFrames within iFrames, and how to access those objects. In a nutshell, here is what worked. I did not use shortened object references to help with keeping it all straight.

First, had to check the main page and capture the Level 1 Frame Name, along with a Random Number that gets assigned per session. This gave me:
mainWindow_[RandomName] and is assigned to local variable lcFrame.

Next, I get an object reference to the top level frame: oFrame = ThisForm.oBrowser.Document.Frames(lcFrame)
Next, I get an object reference to the next level frame: oiFrame = oFrame.Document.Frames(lciFrame) &&lciFrame = iframeMgList_[RandomName]
Next, I get an object reference to the next level frame: oiFramePick1 = oiFrame.Document.Frames("iframeSavePick_" + lcRandomName)
Next, I get an object reference to the next level frame: oiFramePick2 = oiFramePick1.Document.Frames("iframePickList_" + lcRandomName)

Once I have oiFramePick2, I can extract the InnerHTML and get to the data I need.
Hopefully this will help someone when the time comes.

Thanks Rick, and to all,
Steve


Regardless of whether its via COM or JavaScript you have to traverse the hierarchy. I believe you can walk the frames using the windows' parent to get the master framelist, then select the fram and the window from there. This should workin the Web Browser control or IE automation.

+++ Rick ---



Hi All,
I have the name of the iFrame. However, I cannot seem to figure out how to get a reference to the iFrame from within VFP. I am displaying the web page using the Browser Control on a standard VFP Form. I can access the Document Object. I am capturing the iFrame name in a variable called lciFrame.
I see where Rick says to use window.frames[framename], but isn't that JScript?

1) Is it possible to access the content of an iFrame? Or, is this considered XSS and now allowed?
2) What is the syntax???
I can get a reference to the parent frame using: oFrame = o.Document.Frames(lcFrame)
What's the next step to get the InnerHTML for the iFrame?

TIA,
Steve


I think selecting the iFrame doesn't give you the actual frame/window instance. You need to use window.frames[framename] to find the actual frame instance. From there you should be able to say loFrame.document and go on accessing the frame.

Note depending on your security settings you may not be able to script into a frame as it's a potential security issue (cross site scripting).

+++ Rick ---

Hi all,

Using the web-browser control I can get the HTML code from a URL. What do I do though, when I need to get the .innerHTML for one of a series of iFrames?

What might be the syntax to make that work

* locate all iFrames - using TagName
FOR EACH loTag IN o.DOCUMENT.ALL
IF UPPER(loTag.Tagname) == "IFRAME"

* how do I address the InnerHTML of the iFrame itself?

lcResult = loTag.Tagname && here I get "IFRAME", the name


*produce errors
* lcResult = loTag.inhherhtml
* lcResult = lotag.parent.innerhtml
* lcResult = lotag.body.innerhtml

* lcResult = lotag.document.body.innerhtml
* works, but its not the iFrame even though I'm on that particular iFrame element

* what could be the appropriate syntax here to catch the iFrame?
lcResult = lotag.document.body.innerhtml

ENDIF
ENDFOR

Another approach, since I can even access the url of the iFrames could be something like

lchtml= "http://s36.wurzelimperium.de/verkauf.php?kunde=19059542&kundemap=i2.innerhtml" target="top" >http://s36.wurzelimperium.de/verkauf.php?kunde=19059542&kundemap=i2.innerhtml


* or

o.document.frames(1).innerHTML && ? - if I know from the url that it's frame 2 (i1) that I'm dealing with?

Again: what would be the correct syntax for an approach along these lines? Or what would be alternatives?

All this seems to be a question of "how", since I can simply - by right-clicking on the browser - do a save-as (source code) and get the HTML that I'm looking for, but I don't manage to do this under program control.

TIA,

Teddy










Rick Strahl
West Wind Technologies

Making waves on the Web
from Maui

Gravatar is a globally recognized avatar based on your email address. Re: How to address iFrame in Web-Browser Control from VFP
  Steve
  Steve
  Aug 1, 2019 @ 02:17pm

Hi All, I revisited this recently and discovered the code to access the main Frame on the page no longer works. I get a 1426 OLE Error 0x80020101 when I execute the following line:

oFrame = ThisForm.oBrowser.Document.Frames(lcFrame)

I know the name of the frame held in variable lcFrame exists within the page. This code worked perfectly when I first set it up. I access the frame name by using ThisForm.oBrowser.Document.All and scanning thru the html to extract the name of the frame and place it into lcFrame. Any idea what can be causing the 1426 error? I am stumped.

TIA,
Steve

© 1996-2019