最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - windows.open() with data URI close automatically - Stack Overflow

programmeradmin2浏览0评论

I've a html page that generate a csv with the following code:

var encodedUri = encodeURI(csvContent);
window.open('data:text/plain,' + encodedUri,'_blank').focus();

I'm using firefox in local and it generates correctly a new tab with the data in it, but with firefox or chrome, not in local, the window opens and then close almost immediately (no popup alert triggers)

how may I avoid this and get my file with no problems?

I've a html page that generate a csv with the following code:

var encodedUri = encodeURI(csvContent);
window.open('data:text/plain,' + encodedUri,'_blank').focus();

I'm using firefox in local and it generates correctly a new tab with the data in it, but with firefox or chrome, not in local, the window opens and then close almost immediately (no popup alert triggers)

how may I avoid this and get my file with no problems?

Share Improve this question asked Sep 1, 2017 at 11:46 GodTaxistGodTaxist 716 bronze badges 4
  • I am having the same issue, with Firefox. If you have found an answer, please let me know. The site with the issue is ayunami2000.github.io – ayunami2000 Commented Nov 7, 2017 at 16:33
  • Hi! I never found a real answer to this problem, this is why I didn't post nothing, I found, thus, a nice workaround, take a look at danml./download.html, it's a small lib, very effective, it does everything with a simple download(csvContent, 'something.txt', 'data:text/plain,'); – GodTaxist Commented Nov 8, 2017 at 8:47
  • My issue doesn't use downloading; it uses a new window. I could probably use about:blank with injected code, though. Thanks! – ayunami2000 Commented Nov 8, 2017 at 12:43
  • were you able to figure this out? – Nirav Gandhi Commented Nov 21, 2017 at 13:55
Add a ment  | 

3 Answers 3

Reset to default 5

Apparently one of the filter lists that uBlock Origin uses es with a rule that unconditionally blocks any data URI popups. https://github./gorhill/uBlock/issues/2465

This is most probably due to AdBlock extension. I disabled it and that solved the issue for me.

All I know is that if you right click and click "Reopen closed tab" after the popup opens, it'll reopen the popup.

发布评论

评论列表(0)

  1. 暂无评论