Solved

Getting focus on an HTML iframe

Posted on 2002-06-17
17
1,264 Views
Last Modified: 2007-11-27
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)WebBrowser1.Document;

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.

0
Comment
Question by:aksteve
  • 8
  • 8
17 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 7084156
The syntax would be:

WebBrowser.document.iframename.document.formname.fieldname.value
or
WebBrowser.document.iframename.document.formname.fieldname.focus()

0
 
LVL 5

Author Comment

by:aksteve
ID: 7084587
The iframe has no name="value"

It is just:


<iframe frameborder='0' width='300' height='150' scrolling='No' src='http://iframehere.com'></iframe>
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7085811
You can set it's id can't you?

ANyway, you can also use the frames collection and the index.

WebBrowser.document.frames[0].document.formname.fieldname.focus()

0
 
LVL 5

Author Comment

by:aksteve
ID: 7086547
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 :)
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7086655
Try the above. Instead of an id you use it's index.
0
 
LVL 5

Author Comment

by:aksteve
ID: 7086809
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].document.focus();
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7090904
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(ref 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
0
 
LVL 5

Author Comment

by:aksteve
ID: 7093104
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%
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:CJ_S
ID: 7093108
Will check later tonight. Seen the email, had no time yet :-/
0
 
LVL 22

Accepted Solution

by:
CJ_S earned 400 total points
ID: 7093392
Was kinda easy. Same code, just one enhancement. This is the code I used to test.

               mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2) axWebBrowser1.Document;
               object iIndex = 0;
               mshtml.IHTMLWindow2 x = (mshtml.IHTMLWindow2) doc.frames.item(ref iIndex);
               doc = (mshtml.IHTMLDocument2) x.document;
               MessageBox.Show(doc.body.innerText);

CJ
0
 
LVL 5

Author Comment

by:aksteve
ID: 7093533
Hmm seems to work at the 1st url i gave you but it still doesnt at the 2nd url i sent you..
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7093614
0
 
LVL 5

Author Comment

by:aksteve
ID: 7093629
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
0
 
LVL 5

Author Comment

by:aksteve
ID: 7093752
Well you got it and i thank you a bunch!!

0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7093763
But did you get it to work?

CJ
0
 
LVL 5

Author Comment

by:aksteve
ID: 7093780
Sure did :0
0
 

Expert Comment

by:DarrenSchwarz
ID: 14717583
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 :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why, and when, to use Windows Workflow 1 31
MVC5 Dataformat String for Phone not working 3 25
Calling stored proc in EDMX 11 23
XAML: Layout 8 25
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now