Chrome: JavaScript window.open to be Save

Imagine a FTP client written in HTML and JavaScript. This part works. But it would be nice if user can "copy the listing" into clipboard. Turns out that clipboard stuff is not so easy in JS (besides, listings can be huge). So better is to pop up a window with the generated listing, then user can chose to Copy'Paste, or Save the page to disk.

Currently I do:

    my_window = window.open("", "Copy List");
    my_window.document.write('<pre>n'+string+'</pre>');
    my_window.document.close();

Which works. I get a new tab, and the listing I have generated in "string" displays nicely.

But Chrome disables/greyes-out the "Save Page" option. It would be nice if user can save the page (html or txt). What magic is required to open a window/tab and let them save the content?

Since we use WebSockets (key1/key2) this only works in Chrome, no other browsers needed.


事后的方式,但你可以使用这个数据的URI:

window.open("data:text/plain;base64,"+btoa(theCode))

链接地址: http://www.djcxy.com/p/10518.html

上一篇: 如何处理两个赛段去相同的视图控制器?

下一篇: Chrome:JavaScript window.open为保存