Skip to content

Commit 634f125

Browse files
committed
Added window extensions
1 parent 1a1207e commit 634f125

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespace AngleSharp.Js.Dom
2+
{
3+
using AngleSharp.Attributes;
4+
using AngleSharp.Browser;
5+
using AngleSharp.Dom;
6+
using AngleSharp.Dom.Events;
7+
using System;
8+
9+
/// <summary>
10+
/// Defines a set of extensions for the window object.
11+
/// </summary>
12+
[DomExposed("Window")]
13+
public static class WindowExtensions
14+
{
15+
/// <summary>
16+
/// Posts a message.
17+
/// </summary>
18+
[DomName("postMessage")]
19+
public static void PostMessage(this IWindow window, String message, String targetOrigin = "*", Object transfer = null)
20+
{
21+
var ev = new MessageEvent("message", false, false, message, targetOrigin);
22+
var document = window.Document;
23+
var loop = document.Context.GetService<IEventLoop>();
24+
loop.EnqueueAsync(_ => window.Fire(ev));
25+
}
26+
27+
/// <summary>
28+
/// Gets the top window context.
29+
/// </summary>
30+
[DomName("top")]
31+
[DomAccessor(Accessors.Getter)]
32+
public static IWindow Top(this IWindow window) => window.Document.Context?.Creator?.DefaultView;
33+
}
34+
}

0 commit comments

Comments
 (0)