我正在尝试在布局帕格模板的script标签内包含多行JavaScript函数。它需要在script标记中运行,即必须以这种方式完成,并且由于它是节点应用程序中的客户端逻辑,因此不能作为值传递到模板中。
这与普通HTML等效:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '1111111',
autoLogAppEvents : true,
xfbml : true,
version : 'v5.0'
});
};
</script>
<script async defer src="https://connect.facebook.net/en_US/sdk.js"></script>
由于我使用的是哈巴狗而不是纯HTML,所以我无法正确设置格式,并且无法正常工作。哈巴狗docs仅具有非常基本的示例,例如:
script
include script.js
和
script(src='/javascripts/jquery.js')
script(src='/javascripts/app.js')
这是我当前的哈巴狗文件,也是我尝试使其正常工作的最新尝试。
layout.pug
doctype html
html
head
body
script
//works - just testing
- const x = 1
//works - just testing
- function test(){console.log('test')}
//error - not a real error. Seems like syntax
// Content Security Policy: The page’s settings blocked the loading of a resource at http://localhost:3000/favicon.ico
- function testWrapper(){
window.fbAsyncInit = function() {
FB.init({
appId : '1111111',
autoLogAppEvents : true,
xfbml : true,
version : 'v4.0'
});
}
}
- testWrapper()
// not sure if this is working, but I don't think so.
script(async defer src="https://connect.facebook.net/en_US/sdk.js")
我该如何使用它?
这是我要使用here的Facebook JS SDK。
注:由于脚本标签中插入的JS代码的涉入性稍强,我建议这是[[0]的重复项],而不是this。
我正在尝试在布局帕格模板的script标签内包含多行JavaScript函数。它需要在script标签中运行,即必须以这种方式完成,并且不能传递给...script.
起作用,因此不仅是间距。现在,我得到了200个FB SDK,因此它必须可以正常工作。