本文介绍了未捕获的SyntaxError:意外的标识符-Webshare API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在jekyll帖子页面中实现android chrome的网络共享api.下面是我的代码.
I am trying to implement web share api of android chrome in jekyll posts page. Below is my code.
<script>
document.querySelector('share-btn2').addEventListener('click', function() {
console.log('clicked');
if(navigator.share) {
navigator.share({
title: {{ page.title }},
text: {{ page.content }},
url: {{ site.url }}{{ page.url }}
})
.then(() => console.log('Success'))
.catch((error) => console.log('Error sharing', error));
}
});
</script>
但是在控制台上,在行title: {{ page.title }},
上出现了Uncaught SyntaxError: Unexpected identifier
错误.请更正我的代码.谢谢.
But I get an Uncaught SyntaxError: Unexpected identifier
error in console on line title: {{ page.title }},
. Please correct my code. thanks.
推荐答案
似乎您的JavaScript代码未由Jekyll处理.
It's seems that your javascript code is not processed by Jekyll.
请确保在您要处理的任何文件中设置前件.
Be sure to set a front matter in any file your want to be processed.
---
# even an empty front matter is ok
---
<script>
document.querySelector('share-btn2').addEventListener('click', function() {
console.log('clicked');
if(navigator.share) {
navigator.share({
title: '{{ page.title }}',
text: '{{ page.content }}',
url: '{{ site.url }}{{ page.url }}'
})
.then(() => console.log('Success'))
.catch((error) => console.log('Error sharing', error));
}
});
</script>
这篇关于未捕获的SyntaxError:意外的标识符-Webshare API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!