0

I have 3 templates (static html pages).

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).

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).

Basically I am looking for preview functionality using JavaScript or jQuery, so please provide code for the same.

Matt
  • 74,352
  • 26
  • 153
  • 180
ravikanth
  • 3
  • 1
  • 2
  • Okay your solution most likely involves jQuery running on the target window but we have no information on what you've tried or what and where exactly is this dynamic content coming from. – Mike Perrenoud Jul 18 '12 at 09:11

2 Answers2

0

create a test.html page and Paste this code into the HEAD section of your HTML document.

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

<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.

Jigar Pandya
  • 6,004
  • 2
  • 27
  • 45
  • hi jigar pandya,thanks for ur reply,but my requirement is i want to show another template with form data – ravikanth Jul 18 '12 at 09:29
0

if you use window.open() you can give a name to your window and then manipulate the content of that window:

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

haynar
  • 5,961
  • 7
  • 33
  • 53
  • thanks for reply,but my requirement is i want assign some content to middle of template(ur getting template by url like me) – ravikanth Jul 18 '12 at 09:31
  • you just need to change `document.write` part, take a look at DOM functions like `document.createElement()` or `document.body.appendChild()` and so on – haynar Jul 18 '12 at 09:47
  • in my template i have the following snippet.
    {{content}}
    in this instead of {{content}} i need to place some text.how can i solve this problem.plz help me
    – ravikanth Jul 18 '12 at 10:21
  • you can use DOM methods to find the element with a specific id, in this case `id="content"` then change the innerHTML of that element as you wish – haynar Jul 18 '12 at 11:09
  • can u give the code snippet plz.....plz provide code as soon as possible...plz observe one thing ....iam getting the temlate by using url only ........... – ravikanth Jul 18 '12 at 11:13
  • @ravikanth here is the example in jsFiddle: http://jsfiddle.net/wN9WH/10/ I am writing the content of new window manually as I don't have a concrete page to open, you can pass the url of your page to `window.open()` and skip `document.write()` and `document.close()` part – haynar Jul 18 '12 at 11:45