简体   繁体   English

如何使用JavaScript或jQuery提供预览功能?

[英]How to provide preview functionality using JavaScript or jQuery?

I have 3 templates (static html pages). 我有3个模板(静态html页面)。

Based on my selection one template will open in the form of popup. 根据我的选择,一个模板将以弹出形式打开。 I have to add some content to that template when I want to show that template in the form of popup. 当我想以弹出窗口的形式显示该模板时,必须向该模板添加一些内容。 Now I'm showing that templates with using window.open(url) . 现在,我使用window.open(url)展示这些模板。

But I'm not able to add the content to that template while showing in the form of popup (in single word when I click on " preview " button in the form then popup will generate with predefined HTML template with some form data). 但是我无法在以弹出窗口形式显示时将内容添加到该模板(当我单击表单中的“ 预览 ”按钮时,一个字就可以了,弹出窗口将使用带有某些表单数据的预定义HTML模板生成)。

Basically I am looking for preview functionality using JavaScript or jQuery, so please provide code for the same. 基本上,我正在寻找使用JavaScript或jQuery的预览功能,因此请提供相同的代码。

create a test.html page and Paste this code into the HEAD section of your HTML document. 创建的test.html页面,这个代码粘贴到您的HTML文档的HEAD部分。

function displayHTML(form) {
  var inf = form.htmlArea.value;
  win = window.open(", ", 'popup', 'toolbar = no, status = no');
  win.document.write("" + inf + "");
}

Paste this code into the BODY section of your HTML document 将此代码粘贴到HTML文档的BODY部分中

<form>
  <textarea name="htmlArea" cols=45 rows=6></textarea>
  <br>
  <input type="button" value=" view " onclick="displayHTML(this.form)">
</form>

Test it in browser.. 在浏览器中进行测试。

If found helpfull please do the same in your code. 如果发现有帮助,请在您的代码中执行相同的操作。

if you use window.open() you can give a name to your window and then manipulate the content of that window: 如果使用window.open() ,则可以为窗口命名,然后操纵该窗口的内容:

var win = window.open(url, 'mywindow');
win.document.write('<h1>Popup Test!</h1>');

if the window with name 'mywindow' doesn't exist it will open a new one, otherwise it will use the existing window 如果名称为“ mywindow”的窗口不存在,它将打开一个新窗口,否则将使用现有窗口

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM