static public IHTMLElement GetFrame(mshtml.IHTMLDocument2 doc) { IHTMLElement frame = null; mshtml.IHTMLWindow2 window2 = null; try { window2 = doc.parentWindow as mshtml.IHTMLWindow2; if (window2 != null) { return(((mshtml.HTMLWindow2)window2).frameElement as IHTMLElement); } } catch (UnauthorizedAccessException) { //主页面和IFRAME页面处于不同域名的时候会报UnauthorizedAccessException,下面通过IHTMLWindow2->IWebBrowser2 //比较IWebBrowser2和iframe元素url定位iframe SHDocVw.IWebBrowser2 browser = CrossFrameIE.GetIWebBrowser2(window2); mshtml.IHTMLDocument3 parentDoc = browser.Parent as mshtml.IHTMLDocument3; mshtml.IHTMLElementCollection framesCollection = parentDoc.getElementsByTagName("iframe") as mshtml.IHTMLElementCollection; foreach (mshtml.IHTMLElement f in framesCollection) { SHDocVw.IWebBrowser2 wb2 = (SHDocVw.IWebBrowser2)((mshtml.HTMLFrameElement)f); if (wb2.LocationURL == browser.LocationURL) { frame = f as IHTMLElement; break; } } } catch (Exception) { return(null); } return(frame); }
private static DispHTMLDocument getDocumentByFrame(DispHTMLDocument doc, String frameData) { try { FramesCollection frames = Helper.getHelper().getDocumentProperty("frames") as FramesCollection; int index; if (Int32.TryParse(frameData, out index) && frames.length >= index) { return(getFrameDocument(frames.item(index) as IHTMLWindow2)); } else { for (int i = 0; i < frames.length; i++) { Object frameObject = frames.item(i); IHTMLWindow2 frame = (IHTMLWindow2)frameObject; if (frame.name.Equals(frameData)) { frameObject = CrossFrameIE.GetDocumentFromWindow(frame).activeElement.document as DispHTMLDocument; return((DispHTMLDocument)frameObject); } } } } catch { } return(doc); }
private IHTMLDocument3 parseFrameDocument(int index) { object refIndex = (object)index; IHTMLDocument2 htmlDoc = (IHTMLDocument2)webBrowser.Document.DomDocument; IHTMLWindow2 target_mshtmlIHTMLWindow = (IHTMLWindow2)htmlDoc.frames.item(ref refIndex); IHTMLDocument2 target_mshtmlIHTMLDoc = CrossFrameIE.GetDocumentFromWindow(target_mshtmlIHTMLWindow); IHTMLDocument3 doc3 = (IHTMLDocument3)target_mshtmlIHTMLDoc; return(doc3); }
/// 向业务系统发送消息-入口 /// <summary> /// 向业务系统发送消息-入口 /// </summary> /// <param name="msg"></param> public void SendToWeb(string msg, string webpageid, int recount = 0) { Loger.Log4Net.Info("[MainJs] [SendToWeb] 发送网页消息:" + recount + " 次数,指定页面ID:" + webpageid); try { IHTMLWindow2 win = GetIHTMLWindow2ByWebPageID(webpageid); string para = string.Format("&outBoundType={0}", ((int)BusinessProcess.OutBoundType).ToString()); msg += para; //呼入振铃,则弹屏 if (msg.StartsWith("UserEvent=" + UserEvent.Transferred.ToString())) { TimeProgress(null, new string[] { "", "", "start" }); Loger.Log4Net.Info("[MainJs] [SendMesToWeb] 弹屏 " + ConfigurationManager.AppSettings["DefaultURL"] + "/CTI/PopTransfer.aspx"); NewPageForReq(ConfigurationManager.AppSettings["DefaultURL"] + "/CTI/PopTransfer.aspx?" + msg, true); } //发送事件 win.execScript("try{MethodScript('" + msg + "');}catch(e){}", "Javascript"); var subwin = CrossFrameIE.GetFrameWindowObject(win, SendMsgToIframeSubPageName); //给当前Page中iframe子页面发送消息,若子页面没有订阅消息,则不会发送 if (subwin != null && alowReceiveCallMsg_WebpageIDList.Contains(webpageid)) { subwin.execScript("try{MethodScript('" + msg + "');}catch(e){}", "Javascript"); } Loger.Log4Net.Info("[MainJs] [SendMesToWeb] CTIEventMsg msg:" + msg); if (msg.StartsWith("UserEvent=Released")) { CurrentOutBoundTabPageName = ""; Loger.Log4Net.Info("[MainJs] [CurrentOutBoundTabPageName] 挂断清空"); } } catch (Exception ex) { Loger.Log4Net.Error("客户端回调函数出错:" + ex.Message + "|" + ex.StackTrace); //2秒后重新执行,尝试5次 if (recount <= 5) { Thread thread = new Thread(new ThreadStart(() => { Thread.Sleep(2 * 1000); this.Invoke(new Action <string, int>(SendToWeb), msg, recount + 1); })); thread.Start(); } } }
private static DispHTMLDocument getFrameDocument(IHTMLWindow2 frame) { Object frameObject = CrossFrameIE.GetDocumentFromWindow(frame).activeElement.document as DispHTMLDocument; return((DispHTMLDocument)frameObject); }