Home > Net >  Consult a logical problem: USES the webbrowser control, whether need to distinguish between an eleme
Consult a logical problem: USES the webbrowser control, whether need to distinguish between an eleme

Time:10-09

Consult a logical problem: USES the webbrowser control, the need to distinguish whether an element is the iframe element

My way is:
1, at the same time the subscription webBrowser. Document, webBrowser. Document.. The Window Frames. The Document the MouseOver events in
2, in MouseOver event, to distinguish the mouse pointer to the current element HtmlElementEventArgs. ToElement belongs to which the iframe element
3, itself has a technical difficulties: cross domain access iframe, I resolved


Public static class FrameUtility
{
Public static bool CheckContainFrame (this HtmlDocument document, HtmlDocument frameDocument)
{
Foreach (HtmlWindow HtmlWindow in the document. Window. Frames)
{
If (htmlWindow GetDocument ()==frameDocument)
{
return true;
}
}

return false;
}

Public static string BuildFrameXPathPrefix (this HtmlDocument document, HtmlDocument frameDocument)
{
int index=0;
Foreach (HtmlWindow HtmlWindow in the document. Window. Frames)
{
Index++;

If (htmlWindow GetDocument ()==frameDocument)
{
break;
}
}

Return the string. Format (" frame ({0}) # ", the index);
}
}

If (webBrowser. Document. CheckContainFrame (Document))
{
//
//the current document to the iframe, need prefixed with
//
TxtElementXPath. Text=the string. Format (" {0} {1} ", webBrowser. Document. BuildFrameXPathPrefix (Document), xpath);
}
The else
{
//
//save the XPath
//
TxtElementXPath. Text=xpath;
}

The logic of the question now is:
1, at the same time, subscribe to the webBrowser. Document, webBrowser. Document.. The Window Frames. The Document the MouseOver events in
2 and since MouseOver events will be executed twice, unable to judge whether the document for the iframe documents, or the main document
3, iframe is probably the local small, also be full of the whole page (when to frameset)



CodePudding user response:

WebBrowser is a server-side controls, to determine the iframe can only be judged by the injection of js
  •  Tags:  
  • C#
  • Related