Reputation: 777
I'm trying to run this code
String outputFile = "file:///C:/reports/1016.html";
Window.open(outputFile, "Test", "");
Window.open("http://www.bing.com/", "bing", "");
As you can see, outputFile is not a weblink, but a file. Chrome/firefox do not seem to want to open it, they keep opening an about:blank window. I thought I had done it wrong so I added the third line with an actual webaddress which works fine. What am I doing wrong here? can Window.open() not open files?
Upvotes: 0
Views: 3225
Reputation: 10004
To add to Christian Kuetbach's answer:
Most browsers will block it for security reasons except when coming directly from a click event. (Can't find a link supporting that assertion at the moment but it's worth a try)
Try to Window.open from a user click and it should work.
It should be okay when opening a window in the same website (Same origin policy) See https://developer.mozilla.org/en-US/docs/Web/API/window.open
EDIT: For #1: 'window.open' blocked by Firefox and https://support.mozilla.org/en-US/kb/pop-blocker-settings-exceptions-troubleshooting?redirectlocale=en-US&redirectslug=Pop-up+blocker says:
Is the pop-up shown after a mouse click or a key press?
Certain events, such as clicking or pressing a key, can spawn pop-ups regardless of if the pop-up blocker is on. This is so that Firefox doesn't block pop-ups that websites need to work.
Upvotes: 0
Reputation: 16060
I think it is for security reasons.
Try to start chrome browser with disabled security and see what happens:
chromium --disable-web-security
If the local file is shown, you know its for security reasons disabled. (And you can nothing do against it).
Maybe the web debugger shows a warning (F12
)
Upvotes: 2