下面的代碼的想法是它有一個iframe(這是必要的,因爲應用程序有這個html結構)。當父窗口body元素具有類'IntelligenceEnabled'時,iframe將激活所有'a'標記名的行爲(「我是聰明的!」);並且當該類不存在時,iframe上的鏈接將自動禁用。做一個iframe智能?
問題是:代碼運行良好,但有時當用戶在切換後(禁用/啓用)在iframe中點擊「showMessage」鏈接時,這些鏈接會重定向到url(Facebook,yahoo,google ...)沒有顯示消息。或者相反的效果,信息會顯示出來。
我在做什麼錯了? (兩者是相同的網域iframe和父窗口上)
<html>
<script type="tex/javascript" src="/js/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function() {
$("body.IntelligenceEnabled #IamIntelligent").on('load', function() {
$("body.IntelligenceEnabled #IamIntelligent").contents().delegate('.showMessage', 'load', function() {
alert("I'am intelligent");
return false;
});
});
$('#enableIntelligence').click(function() {
$('body').addClass('IntelligenceEnabled');
return false;
});
$('#disableIntelligence').click(function() {
$('body').removeClass('IntelligenceEnabled');
return false;
});
});
</script>
<body>
<iframe id="IamIntelligent" src="/foo.html"></iframe>
<a href="#" id="enableIntelligence">Enable my intelligence!</a>
<a href="#" id="disableIntelligence">Make me gross!!!</a>
</body>
</html>
(/foo.html)
<html>
<body>
<a href="http://www.google.com" class="showMessage">Google</a>
<a href="http://www.facebook.com" class="showMessage">Facebook</a>
<a href="http://www.yahoo.com" class="showMessage">Yahoo</a>
<a href="http://www.microsoft.com" class="showMessage">Microsoft</a>
</body>
</html>
如果父框架能夠在iframe來檢查內容,那麼想象一下,當你瀏覽會發生什麼「www.awesomesite.com」中嵌入一個iframe來www.yourbank.com您已經登錄在不同的選項卡上。 – SecurityMatt 2013-03-26 05:37:38
^相關用戶名 – nathancahill 2013-03-26 06:01:50