2014-09-24 57 views
0

對於「hellow html5-haxe world」測試,我試圖打印當前的URL。不幸的是,似乎沒有辦法使用Haxe js.html.Document類。編譯器的目標是js和一個跟蹤(「hello world」)(它在Chrome開發者控制檯中可見)。在Haxe中處理javascript文檔

根據這一類的文檔,

Each web page loaded in the browser has its own document object. This object serves as an entry point to the web page's content (the DOM tree, including elements such as <body> and <table>) and provides functionality global to the document (such as obtaining the page's URL and creating new elements in the document).

要訪問的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中的「文件」是建立在全局命名空間,允許我們訪問HTML頁面。但是,Haxe似乎沒有像對象那樣的「文檔」,也沒有某個js類的getDocument()靜態函數。

如何訪問js.html.Document類?

回答

2
var doc = js.Browser.window.document; 
var url = doc.URL; //or any other document command supported by the browser. 

(這個答案被埋葬在訪問`js.html.Document`都在[API文檔]中提到的https://groups.google.com/forum/#!topic/haxelang/y084mee_YDw

+1

更多方式http://api.haxe.org/js/html/ Document.html)。 – 2014-09-25 18:21:04