在使用js連接websocket后發(fā)現(xiàn)始終報錯
var ws = new WebSocket("ws://localhost:8080");
ws.onopen = function(){
console.log("open");
}
ws.onmessage = function(e){
console.log(e.data);
}
ws.onclose = function(e){
console.log("close");
}
ws.onerror = function(e){
console.log(error);
}
控制臺錯誤輸出文章來源:http://www.zghlxwxcb.cn/news/detail-702874.html
Refused to connect to 'ws://127.0.0.1:9394/ws' because it violates the following Content Security Policy directive: "default-src 'self'". Note that 'connect-src' was not explicitly set, so 'default-src' is used as a fallback.
在百度搜索無果后在一系列查略測試后發(fā)現(xiàn)在html頭中調(diào)整加入 connect-src ‘self’ ws:;文章來源地址http://www.zghlxwxcb.cn/news/detail-702874.html
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; connect-src 'self' ws:;">
</head>```
到了這里,關(guān)于使用js連接websocket報錯VM4143:11 Refused to connect to ‘‘ because it violates the following Content Securi的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!