首页  编辑  

替换Java脚本中的标准函数

Tags: /C#/界面处理/WebBrowser/   Date Created:

//

using mshtml ;

private void webBrowser1_Navigated( object sender , WebBrowserNavigatedEventArgs e)

{

    IHTMLDocument2 vDocument = ( IHTMLDocument2 )webBrowser1 . Document . DomDocument;

   vDocument . parentWindow . execScript(

        "function alert(str){if(str=='zswang')confirm(str);}" , "javaScript" );

}

//frame

private void webBrowser1_Navigated( object sender , WebBrowserNavigatedEventArgs e)

{

    IHTMLDocument2 vDocument = ( IHTMLDocument2 )webBrowser1 . Document . DomDocument;

    foreach ( IHTMLElement vElement in vDocument . all)

        if (vElement . tagName . ToUpper() == "FRAME" )

       {

            IHTMLFrameBase2 vFrameBase2 = vElement as IHTMLFrameBase2 ;

           vFrameBase2 . contentWindow . execScript(

                "function alert(str){confirm('[' + str + ']');}" , "javaScript" );

       }

}