Let me explain. I use Colorbox to load HTML file and display it in the iframe. The HTML file contains <title>
tag. Is it possible to use that <title>
tag as the title for the Colorbox popup? I could use onComplete
event, but how?
EDIT: I should clarify the code:
Parent 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>
Child HTML:
<!doctype html>
<html>
<head>
<title>The title</title>
</head>
<body>
...
</body>
</html>
Basically I want that Colorbox shows the title from the child HTML code.
Depending on the document, it may not be possible. If the iframed document is on the same domain as your parent document, you should be able to do something like this:
$(document).ready(function(){
$('a.cb').colorbox({
iframe : true,
fastIframe: false,
onComplete: function(){
var title = $('.cboxIframe')[0].contentWindow.document.title;
$('#cboxTitle').text(title);
}
});
});