Find centralized, trusted content and collaborate around the technologies you use most. Connect and share knowledge within a single location that is structured and easy to search. If the file opens up in the browser it replaces the current tab and when you press the back button to return to the page such as with PDFany text stays in the URL. However, if the file is simply downloaded any text gets removed. Since the page doesn't actually reload I am unable javascript download file close window free put code in that might detect what text should be in the URL.
What could be another workaround? The issue I am having is that one link downloads a file that doesn't open in the browser not a PDF javascript download file close window free it causes the text to disappear.
Then, when I click on another link that does open a file in the browser a PDF when I click the back button, the text is gone, but it is what allows my program to know what view to be on.
Use window. This will open up a new tab temporarily to download the file then close it leaving the original page and URL in tact. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow.
Learn more. Using window. Ask Question. Asked 6 years, 4 months ago. Active 6 years, 4 months ago. Viewed 66k times. Improve this question. Christine Christine 2 2 gold badges 12 12 silver badges 32 32 bronze badges. Add a javascript download file close window free. Active Oldest Votes. Improve this answer. That's pretty much what it currently does, can see the tabs open very briefly as it prepares the download and when the file doesn't exist, the tab stays to say so.
I think it depends on the browser. For instance, I've noticed that with Chrome, opening a. Whereas, a. It only opens a new tab for. Sign up or log in Sign up using Google.
Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. How often do people actually copy and paste from Stack Overflow? Now we know. Featured on Meta. Congratulations to the 59 sites that just left Beta. Linked 0. Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled.
Accept all cookies Customize settings.