aksteve
asked on
Getting focus on an HTML iframe
I am trying to gain focus of an iframe in a html document.
Using:
public AxSHDocVw.AxWebBrowser axWebBrowser1;
I can get the document fine and can view it in the broswer control or view the HTML in a textbox.
IHTMLDocument2 HTMLDocument =(IHTMLDocument2)WebBrowse r1.Documen t;
However, I am trying to get focus on the data in the HTML iframe and put the text in that iframe into a string.
Everything works but i cant get anything from the iframe. I seem to only get the text from the main html document.
Any help is appreciated.
Using:
public AxSHDocVw.AxWebBrowser axWebBrowser1;
I can get the document fine and can view it in the broswer control or view the HTML in a textbox.
IHTMLDocument2 HTMLDocument =(IHTMLDocument2)WebBrowse
However, I am trying to get focus on the data in the HTML iframe and put the text in that iframe into a string.
Everything works but i cant get anything from the iframe. I seem to only get the text from the main html document.
Any help is appreciated.
ASKER
The iframe has no name="value"
It is just:
<iframe frameborder='0' width='300' height='150' scrolling='No' src='http://iframehere.com'></iframe>
It is just:
<iframe frameborder='0' width='300' height='150' scrolling='No' src='http://iframehere.com'></iframe>
You can set it's id can't you?
ANyway, you can also use the frames collection and the index.
WebBrowser.document.frames [0].docume nt.formnam e.fieldnam e.focus()
ANyway, you can also use the frames collection and the index.
WebBrowser.document.frames
ASKER
No, i can't set its ID actually.. If I could i definately would..
Basically i am trying to access to text inside a iframe that has no id.. I am not sure if this can be done with DOM or what.. I have yet to figure it out..
Exactly the reason i offer 200 points for this :)
Basically i am trying to access to text inside a iframe that has no id.. I am not sure if this can be done with DOM or what.. I have yet to figure it out..
Exactly the reason i offer 200 points for this :)
Try the above. Instead of an id you use it's index.
ASKER
I think i tried it the way you suggested(and a few other ways) and got errors each time.
Error I got was:
Cannot apply indexing with [] to an expression of type 'mshtml.FramesCollection'
What i used was:
IHTMLDocument2 HTMLDocument = (IHTMLDocument2) axWebBrowser1.Document;
HTMLDocument.frames[0].doc ument.focu s();
Error I got was:
Cannot apply indexing with [] to an expression of type 'mshtml.FramesCollection'
What i used was:
IHTMLDocument2 HTMLDocument = (IHTMLDocument2) axWebBrowser1.Document;
HTMLDocument.frames[0].doc
You need to cast the collection first, just like you've done for the document.
object iIndex = 0;
mshtml.IHTMLWindow2 x = (mshtml.IHTMLWindow2) HTMLDocument.frames.item(r ef iIndex);
(just checked). Now you can access the document of that innerframe again the same way as you've done for the first HTMLDocument.
Regards,
CJ
object iIndex = 0;
mshtml.IHTMLWindow2 x = (mshtml.IHTMLWindow2) HTMLDocument.frames.item(r
(just checked). Now you can access the document of that innerframe again the same way as you've done for the first HTMLDocument.
Regards,
CJ
ASKER
I emailed a piece to you. Although this answer is 90% correct and i will creit you the 200 points.
I will give ya some bonus points if you can get it 100%
I will give ya some bonus points if you can get it 100%
Will check later tonight. Seen the email, had no time yet :-/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hmm seems to work at the 1st url i gave you but it still doesnt at the 2nd url i sent you..
ASKER
There is text hehe.. Click on the iframe and use view source..
Actually if i can just get the source of it that would be fine also.. i cant seem to get anything from the 2nd url
Actually if i can just get the source of it that would be fine also.. i cant seem to get anything from the 2nd url
ASKER
Well you got it and i thank you a bunch!!
But did you get it to work?
CJ
CJ
ASKER
Sure did :0
For all you Emulators out there let me introduce myself Darren Schwarz...I have been doing extensive work re: webbrowser/application interface emulation and I know that the first time I came across "ntlm" authentication I thought my world had caved in on me...however after a few sleepless nights and some old school true programming I discovered the wonders of windows hooks...so...just thought I would put my hand up with humility and say if I can help anyone with Win or Web emulation I would be glad to share the knowledge and hoipefully gain some too... thats it for now ..bye :)
WebBrowser.document.iframe
or
WebBrowser.document.iframe