访问Haxe中的JavaScript文档

问题描述 投票:0回答:1

对于“hellow html5-haxe world”测试,我正在尝试打印当前的URL。不幸的是,似乎没有办法使用Haxe js.html.Document类。编译器针​​对JS和trace("hello world")工作(它在Chrome开发人员控制台中可见)。

根据这个类的文档:

浏览器中加载的每个网页都有自己的文档对象。此对象用作网页内容的入口点(DOM树,包括诸如和之类的元素),并为文档提供全局功能(例如获取页面的URL并在文档中创建新元素)。

要访问该URL,该类中有一个URL字段。

我尝试上课失败了:

var url:String = js.html.Document.URL; //does not work, URL is not static.

var tmp = new js.html.Document(); //does not work, this class has no constructor.
var url:String = tmp.URL;

在JavaScript中,document内置于全局命名空间,允许我们访问html页面。但是,Haxe似乎没有像某些JS类那样的document对象,也没有getDocument()静态函数。

如何访问js.html.Document课程?

javascript html5 haxe
1个回答
2
投票
var doc = js.Browser.window.document;
var url = doc.URL; //or any other document command supported by the browser.

这个答案被埋没在https://groups.google.com/forum/#!topic/haxelang/y084mee_YDw

© www.soinside.com 2019 - 2024. All rights reserved.