NAME

HTML::Object::DOM::Window - HTML Object DOM Window Class

SYNOPSIS

use HTML::Object::DOM::Window;
my $window = HTML::Object::DOM::Window->new || 
    die( HTML::Object::DOM::Window->error, "\n" );

VERSION

v0.2.0

DESCRIPTION

The Window interface represents a window containing a DOM document; the document property points to the DOM document loaded in that window.

A window for a given document can be obtained using the document-defaultView property|HTML::Object::DOM/defaultView.

INHERITANCE

+-----------------------+     +---------------------------+     +---------------------------+
| HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Window |
+-----------------------+     +---------------------------+     +---------------------------+

PROPERTIES

Inherits properties from its parent HTML::Object::EventTarget

DOMMatrix

This always returns undef under perl.

Normally, under JavaScript, this returns a reference to a DOMMatrix object, which represents 4x4 matrices, suitable for 2D and 3D operations.

See also Mozilla documentation

DOMMatrixReadOnly

This always returns undef under perl.

Normally, under JavaScript, this returns a reference to a DOMMatrixReadOnly object, which represents 4x4 matrices, suitable for 2D and 3D operations.

See also Mozilla documentation

DOMPoint

This always returns undef under perl.

Normally, under JavaScript, this returns a reference to a DOMPoint object, which represents a 2D or 3D point in a coordinate system.

See also Mozilla documentation

DOMPointReadOnly

This always returns undef under perl.

Normally, under JavaScript, this returns a reference to a DOMPointReadOnly object, which represents a 2D or 3D point in a coordinate system.

See also Mozilla documentation

DOMQuad

This always returns undef under perl.

Normally, under JavaScript, this returns a reference to a DOMQuad object, which provides represents a quadrilaterial object, that is one having four corners and four sides.

See also Mozilla documentation

DOMRect

This always returns undef under perl.

Normally, under JavaScript, this returns a reference to a DOMRect object, which represents a rectangle.

See also Mozilla documentation

DOMRectReadOnly

This always returns undef under perl.

Normally, under JavaScript, this returns a reference to a DOMRectReadOnly object, which represents a rectangle.

See also Mozilla documentation

clientInformation

This always returns undef under perl.

Normally, under JavaScript, this is an alias for Window.navigator.

See also Mozilla documentation

closed

This always returns undef under perl.

Normally, under JavaScript, this property indicates whether the current window is closed or not.

See also Mozilla documentation

console

This always returns undef under perl.

Normally, under JavaScript, this returns a reference to the console object which provides access to the browser's debugging console.

See also Mozilla documentation

crypto

This always returns undef under perl.

Normally, under JavaScript, this returns the browser crypto object.

See also Mozilla documentation

customElements

This always returns undef under perl.

Normally, under JavaScript, this returns a reference to the CustomElementRegistry object, which can be used to register new custom elements and get information about previously registered custom elements.

See also Mozilla documentation

devicePixelRatio

This always returns undef under perl.

Normally, under JavaScript, this returns the ratio between physical pixels and device independent pixels in the current display.

See also Mozilla documentation

document

Read-only.

Returns a reference to the document that the window contains.

Example:

my $parser = HTML::Object::DOM->new;
$parser->parse_data( $html );
say( $parser->window->document->title );

See also Mozilla documentation

event

Read-only.

Returns the current event, which is the event currently being handled by the JavaScript code's context, or undefined if no event is currently being handled. The Event object passed directly to event handlers should be used instead whenever possible.

See also Mozilla documentation

frameElement

This always returns undef under perl.

Normally, under JavaScript, this returns the element in which the window is embedded, or undef if the window is not embedded.

See also Mozilla documentation

frames

Read-only.

Returns an array of the subframes in the current window.

Example:

my $frameList = $parser->window->frames;

my $frames = $parser->window->frames; # or my $frames = $parser->window->parent->frames;
for( my $i = 0; $i < $frames->length; $i++ )
{
    # do something with each subframe as $frames->[$i]
    $frames->[$i]->document->body->style->background = "red";
}

See also Mozilla documentation

fullScreen

This boolean value is set to false under perl, but you can change it.

Normally, under JavaScript, this property indicates whether the window is displayed in full screen or not.

Example:

if( $parser->window->fullScreen ) {
    # it's fullscreen!
}
else {
    # not fullscreen!
}

See also Mozilla documentation

history

This always returns undef under perl.

Normally, under JavaScript, this returns a reference to the history object.

See also Mozilla documentation

innerHeight

Normally this is read-only, but under perl you can set whatever number value you want.

Under JavaScript, this gets the height of the content area of the browser window including, if rendered, the horizontal scrollbar.

Example:

my $intViewportHeight = $parser->window->innerHeight;

my $intFrameHeight = $parser->window->innerHeight; # or

See also Mozilla documentation

innerWidth

Normally this is read-only, but under perl you can set whatever number value you want.

Under JavaScript, this gets the width of the content area of the browser window including, if rendered, the vertical scrollbar.

Example:

my $intViewportWidth = $parser->window->innerWidth;

# This will return the width of the viewport
my $intFrameWidth = $parser->window->innerWidth;

See also Mozilla documentation

is_property

Provided with a property name and this will return true if it is indeed a window property or false otherwise.

isSecureContext

This is not used under perl, but you can set whatever boolean value you want. By default this returns true.

Normally, under JavaScript, this indicates whether a context is capable of using features that require secure contexts.

See also Mozilla documentation

length

Read-only.

Returns the number of frames in the window. See also "frames".

Example:

if( $parser->window->length ) {
    # this is a document with subframes
}

See also Mozilla documentation

localStorage

This always returns undef under perl.

Normally, under JavaScript, this returns a reference to the local storage object used to store data that may only be accessed by the origin that created it.

See also Mozilla documentation

location

By default, this returns undef, but you can set it to whatever URI you want. If set, it will return a URI object.

Gets/sets the location, or current URL, of the window object.

Example:

say( $parser->window->location ); # alerts "https://example.org/some/where"

$parser->window->location->assign( "https://example.org" ); # or
$parser->window->location = "https://example.org";

Another example:

$parser->window->location->reload();

Another example:

sub reloadPageWithHash() {
    my $initialPage = $parser->window->location->pathname;
    $parser->window->location->replace('http://example.org/#' + $initialPage);
}

See also Mozilla documentation

locationbar

This always returns undef under perl.

Normally, under JavaScript, this returns the locationbar object, whose visibility can be toggled in the window.

See also Mozilla documentation

This always returns undef under perl.

Normally, under JavaScript, this returns the menubar object, whose visibility can be toggled in the window.

See also Mozilla documentation

messageManager

This always returns undef under perl.

Normally, under JavaScript, this returns the message manager object for this window.

See also Mozilla documentation

mozInnerScreenX

This always returns undef under perl.

Normally, under JavaScript, this returns the horizontal (X) coordinate of the top-left corner of the window's viewport, in screen coordinates. This value is reported in CSS pixels. See mozScreenPixelsPerCSSPixel in nsIDOMWindowUtils for a conversion factor to adapt to screen pixels if needed.

See also Mozilla documentation

mozInnerScreenY

This always returns undef under perl.

Normally, under JavaScript, this returns the vertical (Y) coordinate of the top-left corner of the window's viewport, in screen coordinates. This value is reported in CSS pixels. See mozScreenPixelsPerCSSPixel for a conversion factor to adapt to screen pixels if needed.

See also Mozilla documentation

name

Gets/sets the name of the window.

See also Mozilla documentation

This always returns undef under perl.

Normally, under JavaScript, this returns a reference to the navigator object.

See also Mozilla documentation

onerror

Sets the event listener for when error occur on this window interface.

onlanguagechange

Sets the event listener for when the language is changed. This event does not get fired automatically, but you can trigger it yourself. See HTML::Object::DOM::EventTarget

onorientationchange

Sets the event listener for when there is a change of orientation. This event does not get fired automatically, but you can trigger it yourself. See HTML::Object::DOM::EventTarget

onresize

Sets the event listener for when the screen gets resized. This event does not get fired automatically, but you can trigger it yourself. See HTML::Object::DOM::EventTarget

onstorage

Sets the event listener for when the screen storage facility has been changed. This event does not get fired automatically, but you can trigger it yourself. See HTML::Object::DOM::EventTarget

opener

This always returns undef under perl.

Normally, under JavaScript, this returns a reference to the window that opened this current window.

See also Mozilla documentation

outerHeight

Normally this is read-only, but under perl you can set whatever number value you want.

Under JavaScript, this gets the height of the outside of the browser window.

See also Mozilla documentation

outerWidth

Normally this is read-only, but under perl you can set whatever number value you want.

Under JavaScript, this gets the width of the outside of the browser window.

See also Mozilla documentation

pageXOffset

This always returns undef under perl.

Normally, under JavaScript, this is an alias for window.scrollX.

See also Mozilla documentation

pageYOffset

This always returns undef under perl.

Normally, under JavaScript, this is an alias for window.scrollY

See also Mozilla documentation

parent

Read-only.

Returns a reference to the parent of the current window or subframe, if any. By default this returns undef, but you can set it to a window object.

Example:

my $parentWindow = $parser->window->parent;

if( $parser->window->parent != $parser->window->top) {
    # We're deeper than one down
}

See also Mozilla documentation

performance

Read-only.

This always returns undef under perl.

Normally, under JavaScript, this returns a Performance object, which includes the timing and navigation attributes, each of which is an object providing performance-related data. See also Using Navigation Timing for additional information and examples.

See also Mozilla documentation

personalbar

This always returns undef under perl.

Normally, under JavaScript, this returns the personalbar object, whose visibility can be toggled in the window.

See also Mozilla documentation

screen

Read-only.

Returns a reference to the screen object associated with the window.

Example:

use HTML::Object::DOM qw( window screen );
if( screen->pixelDepth < 8 ) {
    # use low-color version of page
} else {
    # use regular, colorful page
}

See also Mozilla documentation

screenX

This always returns undef under perl.

Normally, under JavaScript, both properties return the horizontal distance from the left border of the user's browser viewport to the left side of the screen.

See also Mozilla documentation

screenY

This always returns undef under perl.

Normally, under JavaScript, both properties return the vertical distance from the top border of the user's browser viewport to the top side of the screen.

See also Mozilla documentation

scrollMaxX

This always returns undef under perl.

Normally, under JavaScript, this returns the maximum offset that the window can be scrolled to horizontally, that is the document width minus the viewport width.

See also Mozilla documentation

scrollMaxY

This always returns undef under perl.

Normally, under JavaScript, this returns the maximum offset that the window can be scrolled to vertically (i.e., the document height minus the viewport height).

See also Mozilla documentation

scrollX

Normally this is read-only, but under perl you can set whatever number value you want. BY default this is undef

Under JavaScript, this returns the number of pixels that the document has already been scrolled horizontally.

See also Mozilla documentation

scrollY

Normally this is read-only, but under perl you can set whatever number value you want. BY default this is undef

Under JavaScript, this returns the number of pixels that the document has already been scrolled vertically.

See also Mozilla documentation

scrollbars

This always returns undef under perl.

Normally, under JavaScript, this returns the scrollbars object, whose visibility can be toggled in the window.

See also Mozilla documentation

self

Read-only.

Returns an object reference to the window object itself.

Example:

use HTML::Object::DOM qw( window );
if( window->parent->frames->[0] != window->self )
{
    # this window is not the first frame in the list
}

my $w1 = window;
my $w2 = self;
my $w3 = window->window;
my $w4 = window->self;
# $w1, $w2, $w3, $w4 all strictly equal, but only $w2 will sub in workers

See also Mozilla documentation

sessionStorage

This always returns undef under perl.

Normally, under JavaScript, this returns a reference to the session storage object used to store data that may only be accessed by the origin that created it.

See also Mozilla documentation

This always returns undef under perl.

Normally, under JavaScript, this returns a reference to the window object of the sidebar.

See also Mozilla documentation

speechSynthesis

This always returns undef under perl.

Normally, under JavaScript, this returns a SpeechSynthesis object, which is the entry point into using Web Speech API speech synthesis functionality.

See also Mozilla documentation

status

Normally this is read-only, but under perl you can set whatever text value you want. It returns a scalar object.

Under JavaScript, this gets/sets the text in the statusbar at the bottom of the browser.

Example:

use HTML::Object::DOM qw( window );
window->status = $string;
my $value = window->status;

See also Mozilla documentation

statusbar

This always returns undef under perl.

Normally, under JavaScript, this return the statusbar object, whose visibility can be toggled in the window.

See also Mozilla documentation

toolbar

This always returns undef under perl.

Normally, under JavaScript, this return the toolbar object, whose visibility can be toggled in the window.

See also Mozilla documentation

top

Normally this is read-only, but under perl you can set whatever window object you want.

Under JavaScript, this returns a reference to the topmost window in the window hierarchy. This property is read only.

Example:

use HTML::Object::DOM qw( window );
my $topWindow = window->top;

See also Mozilla documentation

visualViewport

Normally this is read-only, but under perl you can set whatever number value you want.

Under JavaScript, this a VisualViewport object which represents the visual viewport for a given window.

See also Mozilla documentation

window

Read-only.

Returns a reference to the current window.

Example:

use HTML::Object::DOM qw( window );
window->window
window->window->window
window->window->window->window
# ...

my $global = {data: 0};
say( $global == window->global ); # displays "true"

See also Mozilla documentation

METHODS

Inherits methods from its parent HTML::Object::EventTarget

alert

Under perl, this calls "warn" in perlfunc passing it whatever arguments you provide.

Under JavaScript, this displays an alert dialog.

Example:

use HTML::Object::DOM qw( window );
my $parser = HTML::Object::DOM->new;
window->alert( $message );

window->alert( "Hello world!" );
$parser->window->alert( "Hello world!" );

See also Mozilla documentation

blur

This always returns undef under perl.

Normally, under JavaScript, this sets focus away from the window.

See also Mozilla documentation

cancelAnimationFrame

This always returns undef under perl.

Normally, under JavaScript, this enables you to cancel a callback previously scheduled with Window.requestAnimationFrame.

See also Mozilla documentation

cancelIdleCallback

This always returns undef under perl.

Normally, under JavaScript, this enables you to cancel a callback previously scheduled with Window.requestIdleCallback.

See also Mozilla documentation

captureEvents

Registers the window to capture all events of the specified type.

Example:

use HTML::Object::DOM qw( window );
use HTML::Object::Event qw( events );
window->captureEvents( CLICK );
window->onclick = \&page_click;

Note that you can pass a list of events to this method using the following syntax:

window.captureEvents( KEYPRESS | KEYDOWN | KEYUP ).

Although you can still use it, this method is deprecated in favour of "addEventListener" in EventTarget

See also Mozilla documentation

clearImmediate

This always returns undef under perl.

Normally, under JavaScript, this cancels the repeated execution set using setImmediate.

See also Mozilla documentation

close

Under perl, this does nothing in particular, but under JavaScript, this closes the current window.

See also Mozilla documentation

confirm

This always returns undef under perl.

Normally, under JavaScript, this displays a dialog with a message that the user needs to respond to.

See also Mozilla documentation

dump

Under perl, this use "dump" in Data::Dump to print out data provided to the STDERR.

Under JavaScript, this writes a message to the console.

Example:

use HTML::Object::DOM qw( window );
window->dump( $message );

See also Mozilla documentation

find

This always returns undef under perl.

Normally, under JavaScript, this searches for a given string in a window.

See also Mozilla documentation

focus

This always returns undef under perl.

Normally, under JavaScript, this sets focus on the current window.

See also Mozilla documentation

getComputedStyle

This always returns undef under perl.

Normally, under JavaScript, this gets computed style for the specified element. Computed style indicates the computed values of all CSS properties of the element.

See also Mozilla documentation

getDefaultComputedStyle

This always returns undef under perl.

Normally, under JavaScript, this gets default computed style for the specified element, ignoring author stylesheets.

See also Mozilla documentation

getSelection

This always returns undef under perl.

Normally, under JavaScript, this returns the selection object representing the selected item(s).

See also Mozilla documentation

matchMedia

This always returns undef under perl.

Normally, under JavaScript, this returns a MediaQueryList object representing the specified media query string.

See also Mozilla documentation

moveBy

This always returns undef under perl.

Normally, under JavaScript, this moves the current window by a specified amount.

See also Mozilla documentation

moveTo

This always returns undef under perl.

Normally, under JavaScript, this moves the window to the specified coordinates.

See also Mozilla documentation

open

Under perl, this merely returns a new "window object".

Under JavaScript, this opens a new window.

See also Mozilla documentation

postMessage

This always returns undef under perl.

Normally, under JavaScript, this provides a secure means for one window to send a string of data to another window, which need not be within the same domain as the first.

See also Mozilla documentation

print

This always returns undef under perl.

Normally, under JavaScript, this opens the Print Dialog to print the current document.

See also Mozilla documentation

prompt

This always returns undef under perl.

Normally, under JavaScript, this returns the text entered by the user in a prompt dialog.

See also Mozilla documentation

releaseEvents

Releases the window from trapping events of a specific type.

Example:

use HTML::Object::DOM qw( window );
window->releaseEvents( KEYPRESS );

Note that you can pass a list of events to this method using the following syntax:

   window->releaseEvents( KEYPRESS | KEYDOWN | KEYUP );

requestAnimationFrame

This always returns undef under perl.

Normally, under JavaScript, this tells the browser that an animation is in progress, requesting that the browser schedule a repaint of the window for the next animation frame.

See also Mozilla documentation

requestIdleCallback

This always returns undef under perl.

Normally, under JavaScript, this enables the scheduling of tasks during a browser's idle periods.

See also Mozilla documentation

resizeBy

This always returns undef under perl.

Normally, under JavaScript, this resizes the current window by a certain amount.

See also Mozilla documentation

resizeTo

This always returns undef under perl.

Normally, under JavaScript, this dynamically resizes window.

See also Mozilla documentation

scroll

This always returns undef under perl.

Normally, under JavaScript, this scrolls the window to a particular place in the document.

See also Mozilla documentation

scrollBy

This always returns undef under perl.

Normally, under JavaScript, this scrolls the document in the window by the given amount.

See also Mozilla documentation

scrollByLines

This always returns undef under perl.

Normally, under JavaScript, this scrolls the document by the given number of lines.

See also Mozilla documentation

scrollByPages

This always returns undef under perl.

Normally, under JavaScript, this scrolls the current document by the specified number of pages.

See also Mozilla documentation

scrollTo

This always returns undef under perl.

Normally, under JavaScript, this scrolls to a particular set of coordinates in the document.

See also Mozilla documentation

setImmediate

This always returns undef under perl.

Normally, under JavaScript, this executes a function after the browser has finished other heavy tasks

See also Mozilla documentation

setResizable

This always returns undef under perl.

Normally, under JavaScript, this toggles a user's ability to resize a window.

See also Mozilla documentation

showDirectoryPicker

This always returns undef under perl.

Normally, under JavaScript, this displays a directory picker which allows the user to select a directory.

See also Mozilla documentation

showOpenFilePicker

This always returns undef under perl.

Normally, under JavaScript, this shows a file picker that allows a user to select a file or multiple files.

See also Mozilla documentation

showSaveFilePicker

This always returns undef under perl.

Normally, under JavaScript, this shows a file picker that allows a user to save a file.

See also Mozilla documentation

sizeToContent

This always returns undef under perl.

Normally, under JavaScript, this sizes the window according to its content.

See also Mozilla documentation

stop

This always returns undef under perl.

Normally, under JavaScript, this method stops window loading.

See also Mozilla documentation

updateCommands

This always returns undef under perl.

Normally, under JavaScript, this updates the state of commands of the current chrome window (UI).

See also Mozilla documentation

EVENTS

Event listeners for those events can also be found by prepending on before the event type:

click event listeners can be set also with onclick method:

$e->onclick(sub{ # do something });
# or as an lvalue method
$e->onclick = sub{ # do something };

error

Under perl, this is fired when this window object encounters an error.

Under JavaScript, this is fired when a resource failed to load, or cannot be used. For example, if a script has an execution error or an image can't be found or is invalid. Also available via the onerror property.

See also Mozilla documentation

UNSUPPORTED EVENTS

The following events are unsupported under perl, but you can still fire them by yourself using the "dispatchEvent" in HTML::Object::EventTarget

devicemotion

Fired at a regular interval, indicating the amount of physical force of acceleration the device is receiving and the rate of rotation, if available.

See also Mozilla documentation

deviceorientation

Fired when fresh data is available from the magnetometer orientation sensor about the current orientation of the device as compared to the Earth coordinate frame.

See also Mozilla documentation

languagechange

Fired at the global scope object when the user's preferred language changes. Also available via the onlanguagechange property.

See also Mozilla documentation

orientationchange

Fired when the orientation of the device has changed. Also available via the onorientationchange property.

See also Mozilla documentation

resize

Fired when the window has been resized. Also available via the onresize property.

See also Mozilla documentation

storage

Fired when a storage area (localStorage or sessionStorage) has been modified in the context of another document. Also available via the onstorage property.

See also Mozilla documentation

UNSUPPORTED EVENT HANDLERS

Although those event handlers exist, their related events never get fired unless you fire them yourself.

onappinstalled

Called when the page is installed as a webapp. See appinstalled event.

See also Mozilla documentation

onbeforeinstallprompt

An event handler property dispatched before a user is prompted to save a web site to a home screen on mobile.

See also Mozilla documentation

ondevicemotion

Called if accelerometer detects a change (For mobile devices)

See also Mozilla documentation

ondeviceorientation

Called when the orientation is changed (For mobile devices)

See also Mozilla documentation

ondeviceorientationabsolute

An event handler property for any device orientation changes.

See also Mozilla documentation

ondeviceproximity

An event handler property for device proximity event (see DeviceProximityEvent)

See also Mozilla documentation

ongamepadconnected

Represents an event handler that will run when a gamepad is connected (when the gamepadconnected event fires).

See also Mozilla documentation

ongamepaddisconnected

Represents an event handler that will run when a gamepad is disconnected (when the gamepaddisconnected event fires).

See also Mozilla documentation

onrejectionhandled

An event handler for handled Promise rejection events.

See also Mozilla documentation

onuserproximity

An event handler property for user proximity events (see UserProximityEvent).

See also Mozilla documentation

onvrdisplayactivate

Represents an event handler that will run when a display is able to be presented to (when the vrdisplayactivate event fires), for example if an HMD has been moved to bring it out of standby, or woken up by being put on.

See also Mozilla documentation

onvrdisplayblur

Represents an event handler that will run when presentation to a display has been paused for some reason by the browser, OS, or VR hardware (when the vrdisplayblur event fires) — for example, while the user is interacting with a system menu or browser, to prevent tracking or loss of experience.

See also Mozilla documentation

onvrdisplayconnect

Represents an event handler that will run when a compatible VR device has been connected to the computer (when the vrdisplayconnected event fires).

See also Mozilla documentation

onvrdisplaydeactivate

Represents an event handler that will run when a display can no longer be presented to (when the vrdisplaydeactivate event fires), for example if an HMD has gone into standby or sleep mode due to a period of inactivity.

See also Mozilla documentation

onvrdisplaydisconnect

Represents an event handler that will run when a compatible VR device has been disconnected from the computer (when the vrdisplaydisconnected event fires).

See also Mozilla documentation

onvrdisplayfocus

Represents an event handler that will run when presentation to a display has resumed after being blurred (when the vrdisplayfocus event fires).

See also Mozilla documentation

onvrdisplaypresentchange

represents an event handler that will run when the presenting state of a VR device changes — i.e. goes from presenting to not presenting, or vice versa (when the vrdisplaypresentchange event fires).

See also Mozilla documentation

AUTHOR

Jacques Deguest <jack@deguest.jp>

SEE ALSO

Mozilla documentation, W3C specifications, StackOverlow about WindowProxy

COPYRIGHT & LICENSE

Copyright(c) 2021 DEGUEST Pte. Ltd.

All rights reserved

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.