IE延伸/插件/插件javascipt的注射iframe和文件C# [英] IE Extention/Plugin/Addon javascipt injection in iframe and document c#
本文介绍了IE延伸/插件/插件javascipt的注射iframe和文件C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在C#中面临的问题与BHO,使用Javascript不是在iframe中注入。
I am facing issue with BHO in C# ,Javascript not inject in iframe .
的如何获得的<接入; IFRAME>机身采用C ++ / ATL / COM?
的问题是上述使用COM类似像但在这。我想使用C#。
How to get access of <iframe> body using c++/ATL/COM? question is similar like but in this above using com. i want to use C#.
推荐答案
我创建了一个IE浏览器的扩展/插件/插件注入我的自定义JavaScript页面上,以及作为武官的IFrame与文档
I have created a IE extension/Plugin/Addon To inject my Custom JavaScript on page as well as on IFrame attache with the document
所以我在C#创建BHO。在文档完整的事件
So I created BHO in c# . in Document complete Event
private void webBrowser_DocumentComplete(object pDisp, ref object URL)
{
// this is main docuemnt
document = (HTMLDocument)webBrowser.Document;
//-------------------------------------------------------------------------------------
IHTMLElementCollection elcol = document.getElementsByTagName("iframe");
foreach (IHTMLElement _htmlElement in elcol)
{
try
{
//This line is for specific iframe on body
//string fUrl = ((mshtml.HTMLIFrameClass)_htmlElement).IHTMLFrameBase_src;
//if (fUrl.Contains("/v1/api/login?isIframe=true"))
//{
// in this casting HtmlElement HTMLFrameElement
HTMLFrameElement frmelement = (HTMLFrameElement)_htmlElement;
//from HTMLFrameElement Casting as a WebBrowser2 because it will give us body of i frame and works a document .
DispHTMLDocument doc2 = (DispHTMLDocument)((SHDocVw.IWebBrowser2)frmelement).Document;
//no Doc2 is documnt without access denied .. do what ever you want to do
//Here i am checking wheather document having body or not
if (doc2.body != null)
{
//Here i am checking Already injected or not if not then inject my javascript here
if (doc2.getElementById("UniqueDivVishal") == null)
{
IHTMLElement head = (IHTMLElement)((IHTMLElementCollection)doc2.all.tags("head")).item(null, 0);
IHTMLScriptElement scriptObject = (IHTMLScriptElement)doc2.createElement("script");
scriptObject.type = @"text/javascript";
scriptObject.text = Properties.Resources.SearchHelper1;
((HTMLHeadElement)head).appendChild((IHTMLDOMNode)scriptObject);
string div2 = "<div id=\"UniqueDivVishal\"></div>";
doc2.body.insertAdjacentHTML("beforeend", div2);
}
//execute a function from BHO which is in Iframe
doc2.parentWindow.execScript("funcation(){ InitFn(); alert('Hello From Frame')}", "javascript");
}
//}
}
catch (Exception ex)
{
//Handle Exception here //
}
}
}
有关进一步的细节可以联系我:vishalroxx7 @ gmail.com
for further detail you can contact me : vishalroxx7@gmail.com
这篇关于IE延伸/插件/插件javascipt的注射iframe和文件C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文