IE中事件详细解析(二)

这次主要分析在不同的页面下,主要的DWebBrowserEvent2的发生时机。

  • 我们先定义一个最简单的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) 
/* 一下部分是在按了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的个数已经变成一了



posted on 2011-10-02 16:55  一颗麦粒  阅读(7463)  评论(1编辑  收藏  举报

导航