Open New Tab/window And Close Old One June 28, 2023 Post a Comment Here is my current code, but the closeWindow function is executed before the new tab opens. $(document.body).append('Solution 1: I'm not totally sure, but I think you can do something like this:(function(old_window) { $(new_window).load(function() { old_window.close(); }); })(window); CopyThe outer self-calling anonymous function is used to bind the local variable old_window to 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's onload event. So when the new window is loaded, it will close the current window.Solution 2: I have no idea what you're trying to do, but I'm guessing you have to set the source after the onload function to make it fire properly, and since load() is deprecated and you're using the native object anyway, why not just do it in plain js:var iframe = document.createElement('iframe'); iframe.width = '500px'; iframe.height = '500px'; iframe.id = 'pcl_frame'; iframe.style.display = 'none'; //note that not all browsers load hidden content iframe.onload = function() { this.contentWindow.CreateCBTPlayer(data['code'],"new"); closeWindow(); } $('body').append(iframe).attr('src', data['url']); Copy Share Post a Comment for "Open New Tab/window And Close Old One"
Post a Comment for "Open New Tab/window And Close Old One"