对于“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
课程?
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