2014-01-28 58 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!!');