My only problem is that i cant close the current tab. All i want it to do is open a new tab, and then close the current tab. So far a new tab opens (of itself), which then later opens a new tab of itself. The only problem is, well, i cant get the current tab to close. Then i’m stuck with infinite opening tabs. The hard part is, you can only try one run of the edited code before you need to completely restart your “internet explorer” (task manager). Is their any edit to my current program that i know will make it so the current tabs closes after a new one has been opened? All i need help with is closing the current tab.
If you go and decide to change the code you will:
Make sure you don’t have any important tabs opened (besides this one)
Need to allow 's
Need to add jQurey
Hope it works
This is the code in advance
$(document).ready(function() {
if (document.URL !== "https://codepen.io/Mike-was-here123/pen/MOeexP") {
window.open("https://codepen.io/Mike-was-here123/pen/MOeexP");
}
var one = 1;
if (1 === 1) {
window.open("https://codepen.io/Mike-was-here123/pen/MOeexP");
one += 1;
window.close();
}
// my backup closing which still doesn't close.
if (one !== 1) {
self.close();
}
}); // https://codepen.io/Mike-was-here123/full/dZXXWx/ });
Well its going to do it automatically when you open the window, is their any way i can use that as a reference? I already tried a check variable. Why cant it close without a reference if so?
I even tried adding window.close() to the opening tab if statement, and i had to delete the pen because it didn’t work. New pen posted.
IIRC you can’t do anything that affects the current tab such as killing or reloading using a pen since they’re shown via iframe. Debug view removes this limitation.
I don’t have jquery loaded because it would cause tabs to open uncontrollably every time you open the pen (if cookies enabled). I disabled jQurey until i can find a way to close the current tab ( i know how to infinite open one already). Basically i’m trying to open a new tab, and close the current. My code itself opens a new tab of itself, thus, opens a new tab of itself, etc. Now i want to open a new tab AND close the current so you don’t have 419 tabs at once. How can i accomplish this?
I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
$(document).ready(function() {
if (document.URL !== "https://codepen.io/Mike-was-here123/debug/MOeexP") {
window.open("https://codepen.io/Mike-was-here123/debug/MOeexP"); ////Open in debug mode
}
var one = 1;
if (1 === 1) {
window.open("https://codepen.io/Mike-was-here123/debug/MOeexP");
one += 1;
window.close();
}
// my backup closing which still doesn't close.
if (one !== 1) {
self.close();
}
}); // https://codepen.io/Mike-was-here123/full/dZXXWx/ });
Well, you can’t close a tab in Codepen unless you’re in debug mode. window.close does nothing outside of debug mode. This will open a bunch of debug tags but they’ll also close themselves. It’s still going to open faster than it closes but at least it closes.
Update: I made it so it opens 50 tabs then closes 50. You can edit the amount to.
I might add it so you can select how many tabs you want to do.
Here was the code:
$(document).ready(function() {
if (document.URL !== "https://codepen.io/Mike-was-here123/debug/MOeexP") {
window.open("https://codepen.io/Mike-was-here123/debug/MOeexP"); ////Open in debug mode
}
for (var i = 0; i < 50; i++) {
if (i % 2 === 0) {
window.open("https://codepen.io/Mike-was-here123/debug/MOeexP");
}
if (i % 2 === 1) {
window.close();
}
}
});