[英]Chrome Extension background.js only to work if user is cookie is available
I want the background.js to only work if a certain cookie value is available, if it is not, then the popup.html should prompt the user to login. 我希望background.js仅在某个cookie值可用时才起作用,否则,popup.html应该提示用户登录。 I want only the popup.html to come appear only if that cookie value is not available. 我只希望该cookie值不可用时才出现popup.html。 I am not using popup.js, should i use it in this case or it should be enough to embed my script in popup.html. 我没有使用popup.js,在这种情况下应该使用它,还是足以将我的脚本嵌入popup.html中。
Please advise. 请指教。 Thanks! 谢谢!
You can use the chrome.cookies
API to check for presence of specific cookies from your background page. 您可以使用chrome.cookies
API从后台页面检查特定cookie的存在。
You can't embed javascript code in your popup.html, due to the Content Security Policy for Chrome extensions. 由于Chrome扩展程序的内容安全政策 ,您无法将JavaScript代码嵌入popup.html中。 You need to put your code in a separate file like popup.js and include it via <script src="popup.js></script>
您需要将代码放在单独的文件中,例如popup.js,并通过<script src="popup.js></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.