Here is my current code, but the closeWindow function is executed before the new tab opens.
$(document.body).append('<iframe width="500px" height="500px" id="pcl_frame" style="display:none;"></iframe>');
$('#pcl_frame').attr('src', data['url']);
$('#pcl_frame').load(function() {
// Load page
document.getElementById('pcl_frame').contentWindow.CreateCBTPlayer(data['code'],"new");
// Close current windows after the above tab/window opens
closeWindow(); // has a 2 second delay
});
Is there a way to wait for the command above to open the new tab/window first, then close the current tab that was used to open the new window.
Also I can’t change the CreateCBTPlayer function.
Disclaimer
I know what I’m doing isn’t very logical, but it has to be done to get around an old system I have to work with.
I’m not totally sure, but I think you can do something like this:
The outer self-calling anonymous function is used to bind the local variable
old_windowto the current window object. The inner function is a closure that captures that binding and closes the window. This closure is bound to the new window’sonloadevent. So when the new window is loaded, it will close the current window.