2012-12-12 143 views
2

工作,我的iframe:jQueryUI的滑塊不IFRAME

<!DOCTYPE html> 
<html> 
<head> 
</head> 
<body> 
<link rel="stylesheet" type="text/css" href="jquery-ui-1.9.2.custom.css"> 
<div id="slider"></div> 
</body> 
</html> 

,我有頁:

<!DOCTYPE html> 
<html> 
<head> 
<script src="jquery.js"></script> 
<script src="jquery-ui-1.9.2.custom.js"></script> 
<title></title> 
</head> 
<body> 
<iframe id="frame" src="iframe.html" width="800" ></iframe> 
<script type="text/javascript"> 
$(document).ready(function() { 
    $('#frame').contents().find('#slider').slider({ 
     value:2, 
     min: 0, 
     max: 6, 
     step: 1, 
     animate: true, 
     slide: function(event, ui) { 
     } 
    }); 
}); 
</script> 
</body> 
</html> 

我只是想在iframe中的自定義滑塊但這不是工作,我不知道爲什麼。這項工作完美無iframe。

更新:通過調用創建IFRAME

+0

更新。我有Uncaught ReferenceError:沒有定義jQuery jquery-ui-1.9.2.custom.js:351 (匿名函數) – Suhan

+0

有些東西告訴我你不能從父頁面實例化一個滑塊,但你必須做在iframe中。 – adeneo

+0

但是這是什麼原因? – Suhan

回答

0

iframe是一個獨立的HTML頁面(不同的文檔)滑塊功能,無需進入家長的正當安全原因腳本等修復問題。

您需要在iframe html文檔中包含jQuery & jQuery UI,並在該文檔中運行該函數。

這裏的原因進行了全面的寫了起來: http://javascript.info/tutorial/same-origin-security-policy