我们的网站是用Symfony Framework编写的。有一个JavaScript代码,我猜我们的网站加载了两次。
网址:https://www.drberg.com/blog/what-to-eat-for-your-body-type
请访问上述网站,您将了解每次访问时如何加载两次。我不知道出了什么问题。有人建议可能有一些 backgournd-image css选择器强制网站加载两次,但我没有找到任何东西。
<script type="text/javascript">
function createCookie(name, value, days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name, "", -1);
}
var url = window.location.href;
var fullpath = new URL(url).pathname;
var splitpath = fullpath.split("/");
var pathname = splitpath[2] + "/" + splitpath[3];
var jsonObj = [];
var cookie_name = "video_cookie";
var x = readCookie(cookie_name);
if (x) {
var res = x.split(",");
console.log(x);
for (var i = 0; i < res.length; i++) {
if (res.every(x = > x !== pathname))
{
res.push(pathname);
var joinedArray = res.join(",");
createCookie(cookie_name, joinedArray, 7);
$.post(window.location.href, {
update_views: "yes"
});
}
}
} else {
jsonObj.push(pathname);
createCookie(cookie_name, jsonObj, 7);
$.post(window.location.href, {
update_views: "yes"
});
var x = readCookie(cookie_name);
console.log(x);
}
</script>