2

I am actually getting the html template dynamically on the fly, so my concern is how would I be able to append the html code to an iframe's src.

I followed up with some other question in the community and I could make jsFiddle , this is working fine for a single line of html template like

<html><head><title></title></head><body><h1>Hello world.</h1></body></html>

but when I a trying to add the little long length html template then the template is showing out of the iframe ,please check here .

Mohammed Abrar Ahmed
  • 2,290
  • 3
  • 15
  • 33
  • Possible duplicate of [dynamically set iframe src](https://stackoverflow.com/questions/6000987/dynamically-set-iframe-src) – Meloman Sep 11 '17 at 08:46
  • Out there they are just adding the links for src parameter in iFrame which I already mentioned in the question and I have a solution [here](https://jsfiddle.net/0co1gfe8/) – Mohammed Abrar Ahmed Sep 11 '17 at 08:49

1 Answers1

1

Use like below

doc.write('<!DOCTYPE html>'+
    ''+
    '');

Like this

doc.write('<!DOCTYPE html>'+
'<html lang="en">'+
'<head>');

New line is breaking your javascript function

Yogesh
  • 655
  • 5
  • 13
  • I am getting the html template on the fly , I can't add "+" to the lines. – Mohammed Abrar Ahmed Sep 11 '17 at 08:44
  • create function like this post https://stackoverflow.com/questions/805107/creating-multiline-strings-in-javascript – Yogesh Sep 11 '17 at 08:44
  • How you are getting this content in variable? – Yogesh Sep 11 '17 at 08:45
  • yes. actually I have form once the user fills that form we are putting that details as HTML file and then this has to be shown in another page in an iFrame. – Mohammed Abrar Ahmed Sep 11 '17 at 08:56
  • For that you can read that html file in one variable in javascript then you can directly append that variable in iframe in that case it will not be new line but escaped with characters so – Yogesh Sep 11 '17 at 08:57
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/154119/discussion-between-yogesh-and-mohd-abrar-ahmed). – Yogesh Sep 11 '17 at 09:21