Nik*_*huk 3 jquery title colorbox
让我解释.我使用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>
Run Code Online (Sandbox Code Playgroud)
儿童HTML:
<!doctype html>
<html>
<head>
<title>The title</title>
</head>
<body>
...
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
基本上我想要Colorbox显示子HTML代码的标题.
根据文档,可能无法实现.如果iframed文档与父文档位于同一个域中,您应该可以执行以下操作:
$(document).ready(function(){
$('a.cb').colorbox({
iframe : true,
fastIframe: false,
onComplete: function(){
var title = $('.cboxIframe')[0].contentWindow.document.title;
$('#cboxTitle').text(title);
}
});
});
Run Code Online (Sandbox Code Playgroud)