对于" hellow html5-haxe world" test我正在尝试打印当前的URL。不幸的是,似乎没有办法使用Haxe js.html.Document
类。编译器针对JS和trace("hello world")
工作(在Chrome开发人员控制台中可见)。
根据本课程的文件:
浏览器中加载的每个网页都有自己的文档对象。该对象用作网页内容的入口点(DOM树,包括诸如和之类的元素),并为文档提供全局功能(例如获取页面的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似乎没有document
类似对象,也没有某个JS类的getDocument()
静态函数。
如何访问js.html.Document
类?
答案 0 :(得分: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
中