Chrome:JavaScript window.open可以保存 [英] Chrome: JavaScript window.open to be Save-able
问题描述
目前我确实: p>
my_window = window.open(,Copy List);
my_window.document.write('< pre> \\ n'+ string +'< pre>');
my_window.document.close();
其中有效。我收到一个新选项卡,并且我在字符串中生成的列表显示效果很好。
但Chrome禁用/隐藏保存页面选项。如果用户可以保存页面(html或txt),那将会很好。打开一个窗口/选项卡并让它们保存内容需要什么魔力?
由于我们使用WebSockets(key1 / key2),所以只能在Chrome中使用,没有其他浏览器需要。
window.open(data:text / plain; base64,+ btoa(theCode))
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.
Way after the fact but you can use a data URI for this:
window.open("data:text/plain;base64,"+btoa(theCode))
这篇关于Chrome:JavaScript window.open可以保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!