Page 1 of 2

Show HTML in new window from html string

Posted: Tue Apr 07, 2015 1:22 am
by Aeneas McBurney

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


Show HTML in new window from html string

Posted: Tue Apr 07, 2015 2:54 pm
by Serhii Kulibaba

Hello Aeneas,
Please use InAppBrowser for apps on devices


Show HTML in new window from html string

Posted: Tue Apr 07, 2015 7:02 pm
by Aeneas McBurney

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


Show HTML in new window from html string

Posted: Tue Apr 07, 2015 7:18 pm
by Egor Kotov6832188

Hello Aeneas,

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

/pre


Show HTML in new window from html string

Posted: Tue Apr 07, 2015 9:04 pm
by Aeneas McBurney

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


Show HTML in new window from html string

Posted: Wed Apr 08, 2015 5:15 pm
by Serhii Kulibaba

[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


Show HTML in new window from html string

Posted: Wed Apr 08, 2015 6:45 pm
by Aeneas McBurney

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


Show HTML in new window from html string

Posted: Fri Apr 10, 2015 1:46 am
by Yurii Orishchuk

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.


Show HTML in new window from html string

Posted: Mon Apr 13, 2015 7:02 pm
by Aeneas McBurney

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


Show HTML in new window from html string

Posted: Mon Apr 13, 2015 7:44 pm
by Aeneas McBurney

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");