Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Show HTML in new window from html string

I have a string (invhtml) of HTML that I want to display in a new window. I am running the below code which works in the web based app tester but when I run it on my app tester on my android device I get a blank document even though the alert shows the html correctly.

alert(invhtml);
var wnd = window.open("about:blank","_blank","directories=no,status=no,menubar=no,scrollbars=no,resizable=no,EnableViewPortScale=yes");
wnd.document.write(invhtml);

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Show HTML in new window from html string

Hello Aeneas,
Please use InAppBrowser for apps on devices

Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Show HTML in new window from html string

Am I able to write an html string to an Inappbrowser?

Egor Kotov6832188
Posts: 0
Joined: Wed Nov 19, 2014 5:15 pm

Show HTML in new window from html string

Hello Aeneas,

Yes, you can, the issue is in your code.
pre
var wnd = window.open( "","_blank");
wnd.document.write(invhtml);

/pre

Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Show HTML in new window from html string

If I run the above code I get a new window with my startup screen showing not the html string??

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Show HTML in new window from html string

[quote:]
Am I able to write an html string to an Inappbrowser?
[/quote]
Sure

[quote:]
If I run the above code I get a new window with my startup screen showing not the html string??
[/quote]

Change it with:
pre
wnd.document.write(invhtml);
/pre

Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Show HTML in new window from html string

That's exactly what I did and it doesn't work. Your code is no different to mine?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Show HTML in new window from html string

Hi Aeneas,

If you use device to test it you need to work with inAppBrowser object. Actually it's not regular window. Thus you can not access "wnd.document" like in your code.

You can find more info about inAppBrowser here: https://wiki.apache.org/cordova/InApp...

So the solution JS code to write HTML code to new inAppBrowser window is:

precode

var invhtml = '<div style="background: red;">hello world<>';
var wnd = window&#46;open("about:blank","_blank","directories=no,status=no,menubar=no,scrollbars=no,resizable=no,EnableViewPortScale=yes");

wnd&#46;addEventListener( "loadstop", function() {
wnd&#46;executeScript({ code: 'document&#46;write(/code' + invhtml + ');' });
});

/pre

Regards.

Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Show HTML in new window from html string

Will this code still work when running code from browser or do I need to check first and change back to other way?

Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Show HTML in new window from html string

I have the below code which is now not erroring however nothing appears in the window I open?

alert(invhtml);

var wnd = window.open("about:blank","_blank","directories=no,status=no,menubar=no,scrollbars=no,resizable=no,EnableViewPortScale=yes");
wnd.addEventListener( "loadstop", function() {
wnd.executeScript({ code: 'document.write(' + invhtml + ');' });
});

$(this).removeClass('ui-disabled');
$(this).text("View Invoice");

Return to “Issues”