呵呵呵呵呵

萝莉有三好,柔体 轻音 易推倒。女神有三宝,干嘛 呵呵 去洗澡。宅男有三好:Dota 基友 破电脑。


TCppWebBrowser中事件触发顺序与示例

TCppWebBrowser中事件触发顺序与示例


我们先定义一个最简单的html


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
HELLO
</body>
</html>

复制代码

这是,生成的序列如下所示:

[7012] DISPID_BEFORENAVIGATE2 paramCount:7, p0(VT_BOOL):0 p1(VT_BSTR):(null) p3(VT_BSTR):(null) p5(VT_BSTR):http://localhost/mylocalhost/purehtml.html p6(VT_DISPATCH)
[7012] DISPID_DOWNLOADBEGIN paramCount:0,
[7012] DISPID_NAVIGATECOMPLETE2 paramCount:2, p0(VT_BSTR):http://localhost/mylocalhost/purehtml.html p1(VT_DISPATCH)
[7012] DISPID_DOWNLOADCOMPLETE paramCount:0,
[7012] DISPID_DOCUMENTCOMPLETE:paramCount:2, p0(VT_BSTR):http://localhost/mylocalhost/purehtml.html p1(VT_DISPATCH)


可以看到,先触发的是BEFORENAVIGATE2,然后是DownloadBEGIN, NAVIGATECOMPLETE2, DOWNLOADCOMPLETE, DOCUMENTCOMPLETE。

    对于一个引用js和css文件的html文件,源码如下:


<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
    <script type="text/javascript" src="JsFunc.js"></script>
    <link rel="Stylesheet" type="text/css" href="cssBTN.css" />
</head>
<body>
<form>
    <input class="mybtn" type="button" value="dome" onclick="addd();" />
</form>
</body>
</html>


对于一个引用js和css文件的html文件,加载的顺序基本上是一样的。
复制代码

[7012] DISPID_BEFORENAVIGATE2 paramCount:7, p0(VT_BOOL):0 p1(VT_BSTR):(null) p3(VT_BSTR):(null) p5(VT_BSTR):http://localhost/mylocalhost/withjscss.html p6(VT_DISPATCH)
[7012] DISPID_DOWNLOADBEGIN paramCount:0,
[7012] DISPID_NAVIGATECOMPLETE2 paramCount:2, p0(VT_BSTR):http://localhost/mylocalhost/withjscss.html p1(VT_DISPATCH)
[7012] DISPID_DOWNLOADCOMPLETE paramCount:0,
[7012] DISPID_DOCUMENTCOMPLETE:paramCount:2, p0(VT_BSTR):http://localhost/mylocalhost/withjscss.html p1(VT_DISPATCH)


    包含多个frame的html文件如下:

<html xmlns="http://www.w3.org/1999/xhtml" >
<frameset cols="25%,50%,25%">
  <frame src="frame_a.htm" />
  <frame src="frame_b.htm" />
</frameset>
</html>

生成的事件序列如下

[7012] DISPID_BEFORENAVIGATE2 paramCount:7, p0(VT_BOOL):0 p1(VT_BSTR):(null) p3(VT_BSTR):(null) p5(VT_BSTR):http://localhost/mylocalhost/withFrames.htm p6(VT_DISPATCH)
[7012] DISPID_DOWNLOADBEGIN paramCount:0,
[7012] DISPID_BEFORENAVIGATE2 paramCount:7, p0(VT_BOOL):0 p1(VT_BSTR):(null) p3(VT_BSTR):(null) p5(VT_BSTR):http://localhost/mylocalhost/frame_a.htm p6(VT_DISPATCH)
[7012] DISPID_BEFORENAVIGATE2 paramCount:7, p0(VT_BOOL):0 p1(VT_BSTR):(null) p3(VT_BSTR):(null) p5(VT_BSTR):http://localhost/mylocalhost/frame_b.htm p6(VT_DISPATCH)
[7012] DISPID_NAVIGATECOMPLETE2 paramCount:2, p0(VT_BSTR):http://localhost/mylocalhost/withFrames.htm p1(VT_DISPATCH)
[7012] DISPID_NAVIGATECOMPLETE2 paramCount:2, p0(VT_BSTR):http://localhost/mylocalhost/frame_a.htm p1(VT_DISPATCH)
[7012] DISPID_DOWNLOADCOMPLETE paramCount:0,
[7012] DISPID_DOCUMENTCOMPLETE:paramCount:2, p0(VT_BSTR):http://localhost/mylocalhost/frame_a.htm p1(VT_DISPATCH)
[7012] DISPID_NAVIGATECOMPLETE2 paramCount:2, p0(VT_BSTR):http://localhost/mylocalhost/frame_b.htm p1(VT_DISPATCH)
[7012] DISPID_DOCUMENTCOMPLETE:paramCount:2, p0(VT_BSTR):http://localhost/mylocalhost/frame_b.htm p1(VT_DISPATCH)
[7012] DISPID_DOCUMENTCOMPLETE:paramCount:2, p0(VT_BSTR):http://localhost/mylocalhost/withFrames.htm p1(VT_DISPATCH)


IE分别为每个frame和主页面都生成一个BEFORENAVIGATE2 和NAVIGATECOMPLETE2 ,为每个frame均生成一个DOCUMENTCOMPLETE事件。

同时为主页面还生成DwonloadBEGIN和DOWNLOADCOMPLETE2 事件

    对于带有一个iframe的页面:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
    hello
    <iframe src="idx.html"></iframe>
     world
    </body>
    </html>

    生成的序列如下:
    [7012] DISPID_BEFORENAVIGATE2 paramCount:7, p0(VT_BOOL):0 p1(VT_BSTR):(null) p3(VT_BSTR):(null) p5(VT_BSTR):http://localhost/mylocalhost/iframeTest.htm p6(VT_DISPATCH)
    [7012] DISPID_DOWNLOADBEGIN paramCount:0,
    [7012] DISPID_BEFORENAVIGATE2 paramCount:7, p0(VT_BOOL):0 p1(VT_BSTR):(null) p3(VT_BSTR):(null) p5(VT_BSTR):http://localhost/mylocalhost/idx.html p6(VT_DISPATCH)
    [7012] DISPID_NAVIGATECOMPLETE2 paramCount:2, p0(VT_BSTR):http://localhost/mylocalhost/iframeTest.htm p1(VT_DISPATCH)
    [7012] DISPID_NAVIGATECOMPLETE2 paramCount:2, p0(VT_BSTR):http://localhost/mylocalhost/idx.html p1(VT_DISPATCH)
    [7012] DISPID_DOWNLOADCOMPLETE paramCount:0,
    [7012] DISPID_DOCUMENTCOMPLETE:paramCount:2, p0(VT_BSTR):http://localhost/mylocalhost/idx.html p1(VT_DISPATCH)
    [7012] DISPID_DOCUMENTCOMPLETE:paramCount:2, p0(VT_BSTR):http://localhost/mylocalhost/iframeTest.htm p1(VT_DISPATCH)

    可以看出,对于单独的iframe,会生成一次befornavigate和NAVIGATECOMPLETE2,还有一个DOCUMENTCOMPLETE事件,并没有额外的Download相关事件发生。

    带有动态生成iframe的页面:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript" src="JsFunc.js"></script>
</head>
<body>
 <input type="button" onclick="addFrame();" />
 <div id="MydID"></div>
</body>
</html>

js的代码如下:

function addFrame() {
    strFrame = "<iframe src=idx.html></iframe>";
    ele = window.document.getElementById("MydID");
    ele.innerHTML = strFrame;
}

成的序列如下:
[7012] DISPID_BEFORENAVIGATE2 paramCount:7, p0(VT_BOOL):0 p1(VT_BSTR):(null) p3(VT_BSTR):(null) p5(VT_BSTR):http://localhost/mylocalhost/withJsGenFrame.html p6(VT_DISPATCH)
[7012] DISPID_DOWNLOADBEGIN paramCount:0,
[7012] DISPID_NAVIGATECOMPLETE2 paramCount:2, p0(VT_BSTR):http://localhost/mylocalhost/withJsGenFrame.html p1(VT_DISPATCH)
[7012] DISPID_DOWNLOADCOMPLETE paramCount:0,
[7012] DISPID_DOCUMENTCOMPLETE:paramCount:2, p0(VT_BSTR):http://localhost/mylocalhost/withJsGenFrame.html p1(VT_DISPATCH) <br>/*  一下部分是在按了button之后,动态添加的序列 */
[7012] DISPID_BEFORENAVIGATE2 paramCount:7, p0(VT_BOOL):0 p1(VT_BSTR):(null) p3(VT_BSTR):(null) p5(VT_BSTR):http://localhost/mylocalhost/idx.html p6(VT_DISPATCH)
[7012] DISPID_DOWNLOADBEGIN paramCount:0,
[7012] DISPID_DOWNLOADCOMPLETE paramCount:0,
[7012] DISPID_DOCUMENTCOMPLETE:paramCount:2, p0(VT_BSTR):http://localhost/mylocalhost/idx.html p1(VT_DISPATCH)

可以看出,按钮按下之后,会触发一次BEFORENAVIGATE2,但是没有与之对应的NAVIGATECOMPLETE事件。

这块儿要注意,动态生成iframe时,触发的DOCUMENTCOMPLETE所带的参数的pDisp是新iframe的IWebbrowser2接口,而这个新页面中没有frame,所以在这个事件中取到的frame的数量为零,但是主页面的frame的个数已经变成一了

更多内容:

嵌入式ARM微处理器CPU选型注意事项
BCB 动态创建TTabSheet
tcppwebbrowser和twebbrowser差别
TCP连接的半连接与半关闭
网络性能测量概述与netperf测量工具使用方法

本文链接地址:http://www.hehehehehe.cn/i/775.html