关于使用AxWebBrowser自定义浏览器时,遇到JS中使用window.open的问题

Nothing_Hsd 2015-06-09 09:46:11
小弟现在用AxWebBrowser自定义一个浏览器,在开发过程中遇到这样一个问题,当我的自定义浏览器加载的网页function中使用了如下代码时:
window.opener = null;
window.open("", "_self");
会出现问题,出现的问题也很奇怪
截图如下:

会出现红色框框里面这个莫名其妙的窗口,但是这个窗口还打不开,只能直接右键关闭,并且正常应该加载网页的tab页也不显示网页内容,而我查看了网页的document,里面是有内容,并且是正常的网页内容,我怀疑是AxWebBrowser控件的问题
JS源码:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CRM</title>
<script>
function toFull() {
url = 'http://localhost:8088/b.html';
if (window.name != 'IAMP') {
window.opener = 'opener';
var newWin = window.open(url, 'IAMP', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbar=yes,resizable=yes,left=0,top=0');
if (newWin != null && typeof(newWin) != "undefined") {
if (newWin.screenTop >= 10 && newWin.screenLeft >= 10) {
newWin.location = url;
newWin.moveTo(0, 0);
newWin.resizeTo(screen.availWidth, screen.availHeight);
}
window.opener = null;
window.open("", "_self");
window.close();
}
} else {
top.window.moveTo(0, 0);
if (document.all) {
top.window.resizeTo(screen.availWidth, screen.availHeight);
} else if (document.layers || document.getElementById) {
if (top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth) {
top.window.outerHeight = top.screen.availHeight;
top.window.outerWidth = top.screen.availWidth;
}
}
}
}
toFull();
</script>
</head>
<body>
<p>我是一个普通的文本框1:<input type="text" id="txt1"></p>
<p>我是一个普通的文本框2:<input type="text" id="txt2"></p>
<iframe src="iframe.htm" width="300" height="150"></iframe>
<iframe src="iframe1.htm" width="300" height="150"></iframe>

</body>
</html>


只要去掉window.opener = null; window.open("", "_self");这两句就没有任何问题,网页可以正常在自定义浏览器中查看,不知道有没有哪位大神遇到过
...全文
188 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Nothing_Hsd 2015-06-10
  • 打赏
  • 举报
回复
现在发现一个问题,当加载这个AxWebBrowser的TabPage是被选中状态的情况下,是不会有这种情况的,而当他是未被选中的情况下,则会出这种问题,那么AxWebBrowser怎样在TabPage未被加载的情况下,完成正常加载网页呢
Nothing_Hsd 2015-06-09
  • 打赏
  • 举报
回复
我不知道是不是AxWebBrowser这个控件引起的这个问题,也不知道该怎么解决,但是我自己有个思路,不知道对不对,就是想办法拦截JS中window.open()这个函数,如果其中的url参数为空的话就禁止执行,一是思路不知道对不对,二是如果思路是对的,不知道该怎么写代码去实现。。。。。有哪位大神可以帮忙也是好的

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧