Last active
March 3, 2021 13:06
-
-
Save yoni-g/0ae03fd9ec21e62a48555a740caae166 to your computer and use it in GitHub Desktop.
How to force close an opened download file (pdf) tab or page that opened by a link?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function openPage(url) { | |
window.setTimeout(function () { | |
openWindow(url); | |
} ,500); | |
} | |
function openWindow(url) { | |
var tab = window.open(url); | |
if (!url.location.pathname.includes('pdf')){ | |
setTimeout(function () { | |
tab.close(); | |
}, 3000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have written this short js code that makes the job. The script can be editable with how much time to delay the open and close of the page. Also i have added an ‘if’ condition that if the file opened is a pdf file, it will not close the tab.
instructions: