Javascript 如何在 IE 中自动允许被阻止的内容?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7038724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 00:23:10  来源:igfitidea点击:

How to automatically allow blocked content in IE?

javascripthtmlinternet-explorer

提问by Ravichandran Jothi

I am using below code for sample menu.

我正在使用以下代码作为示例菜单。

    <html>
<head>
<title>Tree Demo</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.jstree.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
/*       $("#main").jstree({
                "themes" : {
                    "theme" : "default",
                    "dots" : false,
                    "icons" : false
                },
                "plugins" : [ "themes", "json_data", "ui"],
                "json_data" : {
                    "ajax" : {
                        "url" : "jsondata.json",
                        "data" : function (n) {
                            return { id : n.attr ? n.attr("id") : 0 };
                        }
                    }
                }
        });

         $("#main").bind("open_node.jstree", function (e, data) {
                     // data.inst is the instance which triggered this event
                     console.log(data);
                     console.log($.data(data.rslt.obj[0],"folder_name"));
        });
        $("#main").bind("select_node.jstree", function (e, data) {
             // data.inst is the instance which triggered this event
             console.log(data);
             console.log($.data(data.rslt.obj[0],"folder_name"));
        }); */

         $("#main1").jstree({
                "themes" : {
                    "theme" : "default",
                    "dots" : false,
                    "icons" : false
                },
                "plugins" : [ "themes", "html_data"]
        });

    });
</script>
</head>
<body>
    <div id="main1">
        <ul>
            <li><a href="javascript:void(0)">Home Folder</a>
                <ul>
                    <li><a href="javascript:void(0)">Sub Folder1</a></li>
                    <li><a href="javascript:void(0)">Sub Folder2</a></li>
                </ul></li>
            <li><a href="javascript:void(0)">Shared Folders</a>
                <ul>
                    <li><a href="javascript:void(0)">Shared Folder1</a></li>
                    <li><a href="javascript:void(0)">Shared Folder2</a></li>
                </ul></li>
        </ul>
    </div>
    <div id="main">
    </div>
</body>
</html>

when i run the above code in IE browsers it shows top of the page(below the URL bar) like

当我在 IE 浏览器中运行上面的代码时,它会显示页面顶部(位于 URL 栏下方),例如

" To help protect your security , internet explorer has restricted this webpage from running scripts or Activex controls that could access your computer. click for options.. "

“为了帮助保护您的安全,Internet Explorer 已限制此网页运行可以访问您计算机的脚本或 Activex 控件。单击查看选项..”

when i rightclick and click allowed blocked content, it runs.but i want without this popup message i need to run the code...how can i automatically run this one?...

当我右键单击并单击允许阻止的内容时,它会运行。但我希望没有此弹出消息,我需要运行代码...如何自动运行此代码?...

采纳答案by andyb

I believe this will only appear when running the page locally in this particular case, i.e. you should not see this when loading the apge from a web server.

我相信这只会在这种特殊情况下在本地运行页面时出现,即从 Web 服务器加载 apge 时您不应该看到这一点。

However ifyou have permission to do so, you could turn off the prompt for Internet Explorer by following Tools(menu) → Internet OptionsSecurity(tab) → Custom Level(button) → and DisableAutomatic prompting for ActiveX controls.

但是,如果您有权限这样做,您可以按照工具(菜单)→ Internet 选项安全性(选项卡)→自定义级别(按钮)→ 和禁用ActiveX 控件的自动提示来关闭 Internet Explorer 的提示

This will of course, only affect your browser.

这当然只会影响您的浏览器。

回答by Ray Cheng

There is a code solution too. I saw it in a training video. You can add a line to tell IE that the local file is safe. I tested on IE8 and it works. That line is <!-- saved from url=(0014)about:internet -->

还有一个代码解决方案。我在培训视频中看到过。您可以添加一行来告诉 IE 本地文件是安全的。我在 IE8 上测试过,它工作正常。那条线是<!-- saved from url=(0014)about:internet -->

For more details, please refer to https://msdn.microsoft.com/en-us/library/ms537628(v=vs.85).aspx

更多详情请参考https://msdn.microsoft.com/en-us/library/ms537628(v=vs.85).aspx

<!DOCTYPE html>
<!-- saved from url=(0014)about:internet -->
<html lang="en">
    <title></title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script>
        $(document).ready(function () {
            alert('hi');

        });
    </script>
</head>
<body>
</body>
</html>

回答by Steve Rowe

You have two options:

您有两个选择:

  1. Use a Mark of the Web. This will enable a single html page to load. It See herefor details. To do this, add the following to your web page below the doctype and above the html tag:

    <!-- saved from url=(0014)about:internet -->

  2. Disable this feature. To do so go to Internet Options->Advanced->Security->Allow Active Content... Then close IE. When you restart IE, it will not give you this error.

  1. 使用 Web 标记。这将使单个 html 页面能够加载。有关详细信息,请参见此处。为此,请将以下内容添加到您的网页的 doctype 下方和 html 标签上方:

    <!-- 保存自 url=(0014)about:internet -->

  2. 禁用此功能。为此,请转到 Internet 选项->高级->安全->允许活动内容...然后关闭 IE。当您重新启动 IE 时,它不会给您这个错误。

回答by harrygg

If you are to use the

如果您要使用

<!-- saved from url=(0014)about:internet -->

or

或者

<!-- saved from url=(0016)http://localhost -->

make sure the HTML file is saved in windows/dos format with "\r\n" as line breaks after the statement. Otherwise I couldn't make it work.

确保 HTML 文件以 windows/dos 格式保存,并在语句后使用“\r\n”作为换行符。否则我无法让它工作。

回答by Eddy

Steps to configure IE to always allow blocked content:

将 IE 配置为始终允许被阻止的内容的步骤:

  1. From Internet Explorer, select the Toolsmenu, then the Options...
  2. In the Internet Options dialog, select the Advanced tab...
  3. Scroll down until you see the Securityoptions. Enablethe checkbox "Allow active content to run in files on My Computer".
  1. 在 Internet Explorer 中,选择Tools菜单,然后选择Options...
  2. 在 Internet 选项对话框中,选择 Advanced tab...
  3. 向下滚动,直到看到安全选项。 启用复选框 "Allow active content to run in files on My Computer"

enter image description here

在此处输入图片说明

  1. Close the dialog, and quit Internet Explorer. The changes will take effect the next time you start IE.
  1. 关闭对话框,然后退出 Internet Explorer。这些更改将在您下次启动 IE 时生效。

The Blocked Content is a security feature of Windows XP Service Pack 2. If you do not have SP2 installed, then you will never see this message.

被阻止的内容是 Windows XP Service Pack 2 的一项安全功能。如果您没有安装 SP2,那么您将永远不会看到此消息。

From: How To Allow Blocked Content on Internet Explorer

来自:如何在 Internet Explorer 上允许被阻止的内容

回答by commonpike

Alternatively, as long as permissions are not given, the good old <noscript>tags works. You can cover the page in css and tell them what's wrong, ... without using javascript ofcourse.

或者,只要没有授予权限,旧<noscript>标签就可以工作。您可以用 css 覆盖页面并告诉他们有什么问题,...当然不使用 javascript。

回答by JakeJ

That's something I'm not sure that you can change through the HTML of the webpage itself, it's a client-side setting to tell their browser if they want security to be high. Most other browsers will not do this but from what I'm aware of this is not possible to stop unless the user disables the feature.

这是我不确定您是否可以通过网页本身的 HTML 进行更改的内容,这是一个客户端设置,用于告诉浏览器他们是否希望安全性高。大多数其他浏览器不会这样做,但据我所知,除非用户禁用该功能,否则无法停止。

Does it still do what you want it to do after you click on 'Allow'? If so then it shouldn't be too much of a problem

单击“允许”后,它是否仍会执行您希望它执行的操作?如果是这样,那应该问题不大