简体   繁体   English

使用预填充的 HTML 打开窗口

[英]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:

  • Firefox and all browsers that use the Mozilla Foundation's Gecko rendering engine Firefox 和所有使用 Mozilla Foundation 的 Gecko 渲染引擎的浏览器
  • Safari, Chrome and other WebKit-based browsers Safari、Chrome 和其他基于 WebKit 的浏览器
  • Opera歌剧
  • Konqueror征服者
  • Internet Explorer 8+ (with certain limitations) Internet Explorer 8+(有某些限制)

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.

相关问题 访问控制器中的预填充输入字段 - Accessing pre-filled input fields in controllers React - 无法获得预先填写的表格 - React - Unable to get pre-filled form 使用字体真棒图标 - 如何将多个随机预填充的电子邮件添加到一个按钮? (HTML/Javascript) - using font awesome icon - how to add multiple random pre-filled emails to one single button? (HTML/Javascript) select2:如何向用户正确显示预填充选项? - select2: How to display pre-filled options properly to the user? 使用JQuery对预填充选择字段进行下拉选项验证 - Dropdown option validation for pre-filled select fields with JQuery 在创建模式下预填充了对同一实体的两次查找 - Two lookups to the same entity pre-filled in creation mode 如何自动生成谷歌表单的预填充链接 - How to automatically generate pre-filled links of google forms Textarea不会使用预先填充的值自动调整大小 - Textarea does not auto resize with pre-filled value 如何使用Jade处理可能预先填写的表格? - How can I handle a potentially pre-filled form with Jade? 输入字段:预填充值不可删除,但可扩展 - Input-field: pre-filled value not deletable, but extendable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM