But it turns out that the JavaScript from the site bar.com can only access cookies set by bar.com and not any other.
事实并非如此.重要的是包含< script>的HTML文档. element是,而不是说< script>的JS文件的URL.在src属性中提到.
我怀疑你的问题是你正在访问document.cookies属性名为document.cookie(Singular!)