5

my requirement is when I click to download a file, new tab opens. If the file exists, it will start download and if not, it should close the new tab and show error message.

I have used

window.close()

and it's working fine. Except that, IE11 asks for confirmation :

"the webpage you are viewing is trying to close the tab. Do you want to close this tab?"

this interrupts functionality of system and user does not know why it happened.

Any solution on this?
I have stated the whole scenario so that you can give a solution for any stage.

Thank you.

SurajS
  • 473
  • 7
  • 20

1 Answers1

0

I've seen this alert when you try to use window.close() on a window that the user opens; it's a security measure. You shouldn't be able to close a window through JavaScript that the user opens.

One way around this is by sending a request to a servlet, and returning the file from the servlet. Let me know if this doesn't work for you.

Jonathan Chaplin
  • 2,442
  • 1
  • 18
  • 21