我在Zombie.js
评估将内容写入window
变量的脚本时遇到了一些麻烦。这是一个例子来说明我的意思:
假设我有一个foo.js
执行以下操作的脚本:
window.foo = 'foo';
foo.js
然后我使用zombie.js访问以下html页面(其中包括):
HTML
<!DOCTYPE html>
<html>
<head>
<title>zombiejs test </title>
<script type="text/javascript" src="foo.js"></script>
</head>
<body>
<script type="text/javascript">
console.log(window.foo);
</script>
</body>
</html>
我会假设window.foo
在执行 foo.js 后该变量可用于页面的其余部分,但似乎情况并非如此:
Browser.visit('http://localhost:8087/test.html')
给我undefined
。
发生这种情况是否有任何特殊原因,或者我在这里做错了什么?Zombie.js 是否将脚本评估到不同的上下文中,该上下文与页面运行的上下文不同?