简体   繁体   English

在 Window 上存储 Cookie 卸载(Window.Variable)

[英]Store Cookie On Window UnLoad (Window.Variable)

UPDATE:更新:

I stopped using an array (As I originally was when I first posted this)我停止使用数组(就像我第一次发布这个时一样)


I seem to be having issues with my script.我的脚本似乎有问题。 I don't know why, but when the web page unloads, the window.SpecificURL doesn't save.我不知道为什么,但是当 web 页面卸载时, window.SpecificURL 没有保存。 I know the script to get it is fine, the script to store it is as well.我知道获取它的脚本很好,存储它的脚本也是如此。 Is there something I am missing?有什么我想念的吗? Here is my code:这是我的代码:

        var UWDV = window.UWDV = "UserWindowDataV2"; // What Version Is The User Window Data Stored As
        setTimeout(function(){ // Wait So Stuff Can Load
            if (!window.SpecificURL){ // If Not A Special URL To Load
                window.SpecificURL = GetCookie(UWDV); // Get The User's Last Known State
                var WSURL = window.SpecificURL; // Set Variable
                // if (typeof WSURL[0]!=="string" || WSURL[0].length < 2){SetCookie(UWDV, ["home"]); WSURL = ["home"];} // If It Glitched, Fix Automatically
                console.log(WSURL);
                fillpage(WSURL); // Load Page PC
                mobileload(WSURL); // Load Page Mobile
                window.SpecificURLReady = true;
            }
        }, 100);
        window.addEventListener("unload", function(){SetCookie(window.UWDV, window.SpecificURL);}); // Add Save Page Status Function

(FYI: The fillpage & mobileload functions set window.SpecificURL to whatever the choice was.) (仅供参考:fillpage 和 mobileload 函数将 window.SpecificURL 设置为任何选择。)

(FYI2: This is fired 2 seconds after the website loads) (仅供参考:网站加载后 2 秒触发)

I fixed it by switching from Arrays to save data, to a string.我通过从 Arrays 切换到将数据保存到字符串来修复它。 Sorry for any inconvenience to someone trying to solve this!很抱歉给试图解决这个问题的人带来不便!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM