[英]Open Window with Pre-Filled HTML
Sorry about the odd title, I'm not sure how to phrase the question.对不起,奇怪的标题,我不知道如何表达这个问题。 Basically, I was wondering if it is possible open a new window and fill it with HTML from the front-end rather than code an actual route, db calls, etc. (Yep ultra lazy.) Thinking along these lines...基本上,我想知道是否有可能打开一个新窗口并从前端用 HTML 填充它,而不是编写实际的路由、数据库调用等(是的,非常懒惰。)沿着这些思路思考......
var html = '<!DOCTYPE html><body><h1>Y HALO THAR</h1></body>'
window.open(html);
Am I just wishing upon a star here?我只是在这里向星星许愿吗? Is this even possible?这甚至可能吗?
Edit this answer no longer works because of security features implemented that block certain data:
URIs.编辑此答案不再有效,因为实施了阻止某些data:
的安全功能data:
URI。
See Open a new tab/window and write something to it?请参阅打开新选项卡/窗口并向其写入内容? for working answer工作答案
There is the option to use a dataurl ...可以选择使用dataurl ...
window.open('data:text/html,<!DOCTYPE html><body><h1>Y HALO THAR</h1></body>');
Data URIs are currently supported by the following web browsers:以下 Web 浏览器当前支持数据 URI:
The first thing you need to do is make the popup have a variable -你需要做的第一件事是让弹出窗口有一个变量 -
var popup = window.open('blankPage.html');
var html = '<!DOCTYPE html><body><h1>Y HALO THAR</h1></body>';
popup.document.write(html);
The suggestion to do the following建议做以下事情
window.open('data:text/html,<!DOCTYPE html><body><h1>Y HALO THAR</h1></body>');
no longer works on Chrome due depreciation of the 'data:' allowance.由于“数据:”津贴的折旧,不再适用于 Chrome。
https://developers.google.com/web/updates/2017/03/chrome-58-deprecations#remove_content-initiated_top_frame_navigations_to_data_urls https://developers.google.com/web/updates/2017/03/chrome-58-deprecations#remove_content-initiated_top_frame_navigations_to_data_urls
If you used this previously, your code will now open a blank window instead.如果您以前使用过它,您的代码现在将打开一个空白窗口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.