window.open() 如果打开,则在 IE11 中返回 null

2023-04-19前端开发问题
9

本文介绍了window.open() 如果打开,则在 IE11 中返回 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

在默认设置的 Windows 10 上的 IE 中,如果我从本地计算机上的页面或本地网络上的服务器对外部互联网站点执行 window.open(),我会得到null.

In IE on Windows 10 with default settings, if I perform a window.open() against an external internet site from a page on my local machine or a server on my local network, I get null.

请看下面我的复制品.在 Windows 7 或 Google Chrome 上的 IE 中不会发生这种情况.

See my repro below. This doesn't happen in IE on Windows 7 or Google Chrome.

有趣的是,如果我为 Intranet 区域打开启用保护模式"(这样 Intranet 区域和 Internet 区域中的保护模式相同),那么问题就消失了.但是,我需要它在不要求用户这样做的情况下工作.

Interestingly, if I turn on "Enable Protected Mode" for the Intranet Zone (so that Protected Mode are the same in the Intranet Zone and Internet Zone), then the problem goes away. However, I need this to work without requiring users to do this.

我没有找到任何明确的 Microsoft 文档来解释这种行为.我在 EdgeHTML 问题上提出了 一个问题网站,但想看看 SO 上的社区是否对为什么会发生这种情况有任何见解.

I haven't found any clear Microsoft documentation that explains this behavior. I raised an issue on this on the EdgeHTML issues site, but wanted to see if the community on SO has any insight into why this is happening.

谢谢!

<!DOCTYPE HTML>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <script>
        var popupWindow = null;

        function openWindow() {
            popupWindow = window.open('http://microsoft.com', '_blank', 'left=100;top=100;height=100;width=100');
        }

        function checkWindowStatus() {
            if (popupWindow) {
                document.getElementById('status').innerHTML += '- Truthy reference. Closed? ' + popupWindow.closed + '</br>';
            } else {
                document.getElementById('status').innerHTML += '- Falsy reference: ' + popupWindow + '</br>';
            }
        }
    </script>
</head>

<body>
    <h2>Popup Issue</h2>
    <button onclick="openWindow()">Open Window</button>
    <button onclick="checkWindowStatus()">Check Window Status</button>
    <button onclick="popupWindow.close()">Close Window</button>
    <p id="status"></p>
</body>

</html>

推荐答案

好像保护模式不允许在当前域之外打开新窗口,所以你可以尝试用空白页和之后打开窗口更新位置.

It seems that protected mode doesn't allow to open new window outside of the current domain, so you can try to open the window with a blank page and after update the location.

<script>
    var popupWindow = null;

    function openWindow() {
        popupWindow = window.open('', '_blank', 'left=100;top=100;height=100;width=100');
        popupWindow.location = 'http://microsoft.com';
    }

    function checkWindowStatus() {
        if (popupWindow) {
            document.getElementById('status').innerHTML += '- Truthy reference. Closed? ' + popupWindow.closed + '</br>';
        } else {
            document.getElementById('status').innerHTML += '- Falsy reference: ' + popupWindow + '</br>';
        }
    }
</script>

这篇关于window.open() 如果打开,则在 IE11 中返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

Fatal error: Call to a member function fetch_assoc() on a no
业务场景:使用update语句去更新数据库字段。 原因:update接收值不正确。原来代码: $query = "UPDATE student SET date = now() WHERE id = $id";$result = $mysqli-query($query2) or die($mysqli-error); // 问题出现了在这句 $data = $result-fetch_ass...
2024-12-13 前端开发问题
136

js删除数组中指定元素的5种方法
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22 前端开发问题
182

layui 实现实时刷新一个外部的div
主页面上显示了一个合计,在删除和增加的时候需要更改这个总套数的值: //html代码div class="layui-inline layui-show-xs-block" style="margin-left: 10px" id="sumDiv"spanSOP合计:/spanspan${totalNum}/spanspan套/span/div 于是在我们删除这个条数据后,...
2024-11-14 前端开发问题
156

JavaScript小数运算出现多位的解决办法
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18 前端开发问题
301

JavaScript(js)文件字符串中丢失"\"斜线的解决方法
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转...
2024-10-17 前端开发问题
437

layui table数据表格reload where参数保留
1、创建表格对象 layui.use('table', function () { var table = layui.table; tableObj = table.render({ id: "tableId", url: 'url', //数据接口 elem: '#tableId', page: { limit: 15, limits: [15, 30, 50, 100] }, //开启分页 cols: [[ //表头 ... ]], w...
2024-07-18 前端开发问题
385