Accessing NativeWindow Content in an HTML AIR Application?

I am currently creating an HTML / JS AIR application. The application should display another “window” to the user - depending on whether this is the first time the application is launched or not. This part is actually beautiful, and for this I need the following code:

if(!startUp()) { // this simply returns a boolean from a local preferences database that gets shipped with the .air
        // do first time stuff
        var windowOptions = new air.NativeWindowInitOptions();
            windowOptions.systemChrome = 'none';
            windowOptions.type = 'lightweight';
            windowOptions.transparent = 'true';
            windowOptions.resizable = 'false';
        var windowBounds = new air.Rectangle(300, 300, 596, 490);
        var newHtmlLoader = air.HTMLLoader.createRootWindow(true, windowOptions, true, windowBounds);
            newHtmlLoader.load(new air.URLRequest('cover.html'));
}
else {
    // display default window
    // just set nativeWindow.visible = true (loaded from application.xml)
}

However, I want this to be done is to manipulate the contents of the html from cover.htmlafter loading it. There seems to be a lot of online tutorials on how to move, resize, etc. NativeWindowbut I just want to access the HTML content NativeWindow.

For example, how to add a new paragraph to this page? I tried the following:

newHtmlLoader.window.opener = window;               
var doc = newHtmlLoader.window.opener.document.documentElement;

Using the AIR Introspector console, ... .log(doc)returns [object HTMLHtmlElement].

Hmm, seems promising? Then I will try:

var p = document.createElement('p');
var t = document.createTextNode('Insert Me');
p.appendChild(t);
doc.appendChild(p);

... . doc:

var doc = newHtmlLoader.window.opener.document.body; // .log(doc) -> [object HTMLBodyElement]
var doc = newHtmlLoader.window.opener.document; // .log(doc) -> Error: HIERARCHY_REQUEST_ERR: DOM Exception 3

... jQuery:

$(doc).append('<p>Insert Me</p>'); // again, nothing

, - - NativeWindow? .

+3
2

, , , , , ... :

var newHtmlLoader = air.HTMLLoader.createRootWindow(true, windowOptions, true, windowBounds);
newHtmlLoader.addEventListener(air.Event.COMPLETE, doEventComplete);
newHtmlLoader.load(new air.URLRequest('cover.html'));

( , jQuery) , :

function doEventComplete(event) {
    doc = $(event.currentTarget.window.document.body);
    doc.append('<p>Insert Me!</p>')
}

:)

+2

, :

newHtmlLoader.window.opener = window;               
var doc = newHtmlLoader.window.opener.document.documentElement;

set var doc = window.document.documentElement;, 'doc' - , , .

,

var doc = newHtmlLoader.window.document.documentElement;

, , .

0

Source: https://habr.com/ru/post/1743006/


All Articles