让我解释一下。我使用Colorbox加载HTML文件并将其显示在iframe中。HTML文件包含<title>
标记。是否可以使用<title>
标记作为Colorbox弹出窗口的标题?我可以使用onComplete
事件,但是如何使用呢?
编辑:我应该澄清一下代码:
父HTML:
<!doctype html>
<html>
<head>
<title>This is parent</title>
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('a.cb').colorbox({
iframe : true,
title : function() { /* here goes the code */ },
});
});
</script>
</head>
<body>
<a class="cb" href="popup.html">Popup</a>
</body>
</html>
子HTML:
<!doctype html>
<html>
<head>
<title>The title</title>
</head>
<body>
...
</body>
</html>
基本上,我希望Colorbox显示子HTML代码中的标题。
发布于 2012-06-28 02:09:07
根据文档,这可能是不可能的。如果iframed文档与您的父文档在同一个域中,您应该能够执行以下操作:
$(document).ready(function(){
$('a.cb').colorbox({
iframe : true,
fastIframe: false,
onComplete: function(){
var title = $('.cboxIframe')[0].contentWindow.document.title;
$('#cboxTitle').text(title);
}
});
});
发布于 2012-06-27 17:21:41
很难说,但我的猜测是这样的
var titleText = $(fetchedHTML).find('title').text();
发布于 2012-06-27 17:35:20
我不确定我是否很好地理解了你的问题,如果我离开主题很远,请告诉我删除我的帖子:)
您可以通过一个函数来设置颜色框标题,在该函数中,您可以获得iframe标题并将其设置为颜色框标题
$("mycolorbox").colorbox({rel: 'gal', title: function(){
var title = $( "#frame_id").contents( ).find( "title").html( );
return 'title';
}});
我不确定代码是否完全正确,但它可能会有所帮助:)
https://stackoverflow.com/questions/11222866
复制相似问题