Maybe I was a bit unclear. The following script should be copied “as is” to your header.php:
<script type="text/javascript">
var openShadowbox = function(content, player, title){
Shadowbox.open({
content: content,
player: player,
title: title
});
};
</script>
Afterwards, you can use the function to load something:
openShadowbox('https://www.martinbennett.com/uploads/portfolio/index.html', 'html', 'Martin Bennett - Photographer');
But how should the parser know, when exactly to load the function. Well… that’s really a bit tricky.
function callOpenShadowbox() {
openShadowbox('https://www.martinbennett.com/uploads/portfolio/index.html', 'html', 'Martin Bennett - Photographer');
}
if(window.onload) {
var temp = window.onload;
window.onload=function(e) {
temp(e);
callOpenShadowbox();
};
}
else{
window.onload=function(e) {
callOpenShadowbox();
};
}
The window.onload
method can only be applied once, so we need to re-apply the old script (load the Shadowbox script) and add the new script (open the box directly onload).
I couldn’t test anything yet, but basically, the code should work.
— below this, there’s a bit offtopic stuff —
Everything would be alot easier, but Microsoft does not implement the standard way “addEventListener” and has its own function “attachEvent”. Loading only two scripts, it would a bunch too much code to do it the “nice” way:
/* for Mozilla/Safari(?)/Opera9*/
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", init, false);
}
/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
if (this.readyState == "complete") {
init(); // call the onload handler
}
};
/*@end @*/
/* fallback for other browsers */
window.onload = init;
(init = function to load)
See? ??