0

我想为同一域中的多个 URL 获取安全区域(Int​​ernet 区域/本地 Intranet)。我认为最好的解决方案是通过 iFrame 来解决这个问题。@Teemu。代码现在可以工作了。非常感谢你。但到目前为止有一个问题:它显示错误的文本。尽管该页面位于受信任区域(本地 Intranet)中,但他显示“不受信任”(Internet 区域)。知道为什么吗?

<html>
<head>
<script type="text/javascript">


function getZone() {
    var text = new Array();
    document.getElementsByClass('iframeNames');

var test;
for (var i = 0; i < document.frames.length; i++) {
try {
    test = document.frame[i].contentWindow.document;
    text[i] = "Trusted (Local Intranet)";
} catch (e) {
    text[i] =  "Untrusted (Internet Zone)";
}
} //end-for

    var showText = getElementsByClass("zone");
    for (var i = 0; i < showText.length; i++) {
        setText(showText[i], text[i]);
    };
} //end getZone()

function setText(showText, text) {
    showText.innerHTML = text;
} //end setText

if (document.getElementsByClassName) {
    getElementsByClass = function (classList, node) {
        return (node || document).getElementsByClassName(classList);
    };
}

</script>
</head>

<style type="text/css">
tr:nth-child(2n) {
    background-color: #ddd;
}
.format {
    background-color: #ffff;}

#formatierung {
margin-left: 10px;
margin-top: 30px;
font-family: Arial;
font-size: 13px;

}

</style>

<body>

<iframe src = "http://example.com" class = "iframeNames" width = "0" 
height ="0"></iframe>
<iframe src = "http://example.com/index/" class = "iframeNames" width = "0" 
height =  "0"></iframe>

<script type = "text/javascript">
window.onload = function() {

getZone();

};
</script>


<div id = "formatierung">

<table width = "100%">


<tr class = "format"><td><h2>System</h2></td><td><h2>Check Security-Zone</h2></td></tr>
<tr><td>example1</td><td class = "zone"></td></tr>
<tr><td>example2</td><td class = "zone"></td></tr>

</table>
</div>


</body>
</html>
4

1 回答 1

0

你可以试试这个:

var test;
for (var i = 0; i < document.frames.length; i++) {
    try {
        test = document.frames[i].document;
        text[i] = "Trusted (Local Intranet)";
    } catch (e) {
        text[i] =  "Untrusted (Internet Zone)";
    }
}

使用此代码,您根本不需要isTrustedIE()

就像我在之前的评论中所说的那样,frames[]是文档中“窗口”对象的集合。这段代码只是检查它是否可以documentiframe. 这是不可能的,当iframe's 的内容是从跨域源加载时。

于 2012-12-11T07:19:17.527 回答