Jquery 从iframe调用父级中的Fancybox
我有两个页面,我的index.html和social.html。我清理了我的索引,只留下jquery代码,因为我正在尝试在social.html中包含图像,当单击它时,它将打开fancybox并显示它,但在index.html中,而不是在iframe中。出现的错误是:Jquery 从iframe调用父级中的Fancybox,jquery,html,iframe,fancybox,Jquery,Html,Iframe,Fancybox,我有两个页面,我的index.html和social.html。我清理了我的索引,只留下jquery代码,因为我正在尝试在social.html中包含图像,当单击它时,它将打开fancybox并显示它,但在index.html中,而不是在iframe中。出现的错误是: Uncaught TypeError: Property 'showImage' of object [object DOMWindow] is not a function (anonymous function)social.
Uncaught TypeError: Property 'showImage' of object [object DOMWindow] is not a function
(anonymous function)social.html:103
onclick
这是我的index.html:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.fancybox-1.3.4.pack.js"></script>
<link rel="stylesheet" type="text/css" href="css/jquery.fancybox-1.3.4.css" media="screen" />
<script type="text/javascript" src="js/video.js"></script>
<script type="text/javascript">
function showImage(image) {
$.fancybox('<img src="img/' + image + '" alt="" border="0" />');
};
</script>
</head>
<body>
<iframe src="social.html" scrolling="no" border="0" width="579" height="505" allowtransparency="true"></iframe>
</body>
</html>
由于img位于iframe上,因此它是一个不同的网页。因此Jquery在index.html上,但img没有,这就是为什么Jquery无法访问图像 也许用这样的东西。。。但我认为这不管用 关于index.html脚本部分
$(document).ready(function () {
//function to active fancybox on the thumbs class inside the iframe
//Not sure it works on iframes, probably it doesnt.
$("#iframeID.thumbs").fancybox();
});
并将id添加到iframe声明中