2014-01-28 57 views
1

的特性 '的textContent' 我已經創建了一個inline webworker如下:內嵌webworker:無法讀取空

var blob = new Blob([document.querySelector("worker").textContent]); 
var worker = new Worker(window.URL.createObjectURL(blob)); 

但是我得到一個錯誤:

Cannot read property 'textContent' of null 

我缺少什麼?

jsFiddle

回答

2

querySelector模式不匹配任何東西。
我想你應該將其更改爲:

document.querySelector("#worker") // <- Added # to match the id 
+0

現在它拋出一個錯誤:'未捕獲的SyntaxError:意外的標識' –

+0

@RahulDesai那是另一回事。您應該發佈另一個問題,因爲這是另一個問題。 – Florent

+0

http://stackoverflow.com/questions/21403904/inline-webworker-uncaught-syntaxerror-unexpected-identifier –

0

以我爲例,我曾錯誤地認爲我的網頁中刪除HTML代碼。 由於找不到h1標籤,我得到了同樣的錯誤。

所以問題基本上是這樣的;它無法找到html控件,因此無法讀取html屬性textContent。

所以這是我的HTML(我加回來,工作得很好);

<h1>Welcome to app!!</h1> 

這是我的茉莉花測試代碼;

expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!!');