找回密码
 加入
搜索
查看: 9275|回复: 40

[IE类操作] IEEvent_NewWindow3如何使用

 火.. [复制链接]
发表于 2010-12-19 17:59:47 | 显示全部楼层 |阅读模式
装了搜狗浏览器后IEEvent_NewWindow3 、IEEvent_NewWindow2无法使用,原因是网页中有window.open函数,如何屏蔽这个函数?
MSDN的说法如下:
The event is raised during the following actions:

The user clicks a link while pressing the SHIFT or CTRL key.
The user right-clicks a link and selects Open in New Window or Open in New Tab.
There is a targeted navigation to a frame name that does not yet exist, or _blank.
Script invokes window.open.
A browser application calls Navigate or Navigate2 with the navOpenInNewWindow flag.
The application that processes this notification can respond in one of three ways:

Create a new, hidden, non-navigated WebBrowser object or InternetExplorer object that is returned in ppDisp. On return, the object that fired this event configures and navigates (including a BeforeNavigate2 event) the new object to the target location.
Cancel the navigation by setting Cancel to VARIANT_TRUE.
Do nothing and do not set ppDisp to any value. This will cause the object that fired the event to create a new InternetExplorer object as a separate (non-hosted) process to handle the navigation.
按照madn应该是window.open不起作用才对的啊
发表于 2010-12-19 18:12:49 | 显示全部楼层
重定义不知可不可
最后写入网页
<script>window.open = function winopen() {return false;}</script>
 楼主| 发表于 2010-12-19 19:18:21 | 显示全部楼层
怎么写啊?来段代码看看。我没成功
发表于 2010-12-19 21:05:29 | 显示全部楼层
这是禁止网页点击的,上面给的只是个想法(好不好用就不知,多年不玩了,忘光了)
$oBody = _IETagNameGetCollection($oIE, "body", 0)
_IEDocInsertHTML($oBody, "<script>document.body.onclick=function nopopup(){return false;}</script>", "beforeend")
发表于 2010-12-19 21:10:23 | 显示全部楼层
需要好好看看才行
 楼主| 发表于 2010-12-19 21:15:59 | 显示全部楼层
我是这么搞的
#NoTrayIcon
#include <IE.au3>

Do
$IE = _IECreateEmbedded()
_IELoadWaitTimeout(15000)
_IEPropertySet($IE, 'silent', True)
GUICreate("", 800,600)
GUICtrlCreateObj($IE, 0, 0, 800, 600)
GUISetState()
_IENavigate($IE, "About:Blank")

Until Not @error

_IENavigate($IE, "http://mp3.baidu.com/", 0)
IEHeadInsertScript($IE, "function trackMouseover(){return;}")
IEHeadInsertScript($IE, "function window.open(){return False;}")

Sleep(10000)

Func IEHeadInsertScript($o_object, $s_script)
    Local $o_head, $o_element
    $o_head = _IETagNameGetCollection($o_object, "head", 0)
    $o_element = $o_object.document.createElement('script')
    $o_element.type = 'text/javascript'
    $o_element.text = $s_script
    Return $o_head.appendChild($o_element)
EndFunc
 楼主| 发表于 2010-12-19 21:21:02 | 显示全部楼层
还是不行

Func IEEvent_BeforeNavigate2($pDisp,$URL, $Flags, $TargetFrameName, $PostData, $Headers, $Cancel)
_IEHeadInsertEventScript ($oIE, "document", "oncontextmenu", "alert('请用左键下载');return false")
_IEHeadInsertEventScript($oIE,'document','onclick',_Evt__onClick())

                $firturl = $URL       
$oBody = _IETagNameGetCollection($oIE, "body", 0)

_IEDocInsertHTML($oBody, "<script>window.open(){return false;}</script>", "beforebegin")
EndFunc
 楼主| 发表于 2010-12-19 21:30:31 | 显示全部楼层
终于搞定了,是脚本要声明是java script 类型才可以
$oBody = _IETagNameGetCollection($oIE, "body", 0)

_IEDocInsertHTML($oBody, '<SCRIPT type="text/javascript">window.open(){return false;}</script>', "beforebegin")
 楼主| 发表于 2010-12-19 21:33:34 | 显示全部楼层
不过有的地方还是不行,有点不通用
 楼主| 发表于 2010-12-19 23:01:29 | 显示全部楼层
经过测试,在网页中插入
<SCRIPT language=jscript   for=window defer type=text/javascript>function window.open(){return false;}</SCRIPT>
可以屏蔽window.open
可是使用_IEHeadInsertEventScript($oIE,'window','','function window.open(){return false;}')
插入得到的是
<SCRIPT language=jscript  event="" for=window defer type=text/javascript>function window.open(){return false;}</SCRIPT>
event事件不知道如何设置
发表于 2010-12-19 23:02:08 | 显示全部楼层
是要绝对处理的工程庞大
由于网页设计格式的不同(不知这样说对不对)
要设计相应的方法进行处理
不是简单1\2句代码就能全部搞定的
发表于 2010-12-19 23:28:16 | 显示全部楼层
event="onload"
是不是说网页加载完成了就。。。执行某一动作!
 楼主| 发表于 2010-12-19 23:31:35 | 显示全部楼层
还真是,问题解决了一半了,多谢关注
 楼主| 发表于 2010-12-19 23:33:19 | 显示全部楼层
Target=“_blank " 这种新窗口还不知道如何搞定,概叹接着搞吧。
发表于 2010-12-19 23:34:37 | 显示全部楼层
有没有想过用正则去替换掉整个网页内容中不需要的内容,然后重写
不知能否行得通
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-1 11:36 , Processed in 0.079564 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表