我没有找到加载预览时的自定义程序API事件。以下是iframe上有加载事件的解决方案:
// Assures that the code gets runned once per load.
var code_has_run = false;
function preview_loader(){
// When the customizer has loaded the iframe does not
// exist yet. This checks if the iframe exists.
if (jQuery(\'#customize-preview iframe\').length > 0){
// When iframe/preview has loaded.
jQuery(\'#customize-preview iframe\').on(\'load\', function (){
// Wait a little until old frame is removed.
setTimeout(function (){
if (code_has_run == false){
// Code to be run when preview has loaded and is ready.
alert(\'Preview loaded\');
}
code_has_run = true;
// Wait until multiple load events are finished.
setTimeout(function(){
code_has_run = false;
}, 1000);
}, 1000);
});
}
}
jQuery(window).load (function() { // Customizer loaded...
//Call preview_loader if the preview loads under 500ms.
preview_loader();
setInterval(preview_loader, 500);
}