' uckulting typeError'仅在第一页上仅在桌面上的Chrome中加载。在第二或多个页面加载上工作。怎么了?

发布于 2025-01-23 15:17:48 字数 1591 浏览 0 评论 0原文

我有一个问题,只有在桌面上的Chrome中的第一页加载中存在。它在第二页或多个页面加载中在Chrome中起作用。它还可以在每个页面加载下在Chrome的移动设备上工作。

在大多数情况下,它在Safari和Firefox中正常工作。我在那里也遇到了以下错误,只有在第一页加载下,仅在桌面上,但是我无法在那里重现大约一整天。

有人知道发生了什么吗?

我唯一能想到的是触发我的重定向函数。因为正如您在下面指示的第6个流程中看到的那样,在错误之后,该页面将重定向回到index.html。但是,只有当我的SessionStorage值之一是null的值时,该功能才会触发,并且在浏览器控制台中可以看到,当我按下按钮进入下一页时,将正确设置这些值。

错误:

”错误代码的图片

流量:

  1. 带有单独的index.js
  2. 登录页面是index.html,在选择几个下拉词时, ,3个值存储在SessionStorage
  3. 下一页中,称为:ander-quiz.html带有单独的normal-quiz.js
  4. sessionStorage的formal-quiz.html被检索到滤波数据阵列
  5. 中的loadquiz函数在过滤后的数组上运行,并将问题元素设置为对象的'egnerne' 属性
  6. '首页加载的
  7. ,仅在桌面上的Chrome中,上述错误发生,这会使浏览器返回index.html和SessiveStorage ,如果我再次尝试上述内容,它无需问题而没有问题。

线生成错误是我的位置。使用LoadQuiz函数将我的HTML中的问题元素的值设置为已过滤阵列中第一个对象的“英语”属性值。

代码(JS):

function redirect() {
if (selectedBook !== null) {
    // do nothing
} else {
    window.location = "<myURL>"
};
};

redirect();

function loadQuiz() {
const currentQuizData = quizArr[currentQuiz]; // currentQuiz is the question counter. It starts at 0 to get the first object, then increments by 1 after each question

questionEl.innerText = currentQuizData.english;
// line above is where the error is generated

counter.innerText = (currentQuiz + 1) + "/" + quizArr.length;
};
loadQuiz();

I have this problem that only exists on first page load in Chrome on desktop. It works in Chrome on the second or more page loads. It also works on mobile in Chrome on every page load.

It works fine in Safari and Firefox, MOST OF THE TIME. I have experienced the below error there as well, only on first page load, only on desktop, but I am not able to reproduce it there for about an entire day now.

Does anyone know what is going on?

The only thing I have been able to come up with is that somehow my redirect function is triggered. Because as you can see in the flow indicated below at number 6, after the error, the page redirects back to index.html. However that function would only trigger if the value of one of my sessionStorage values is null and I can see in the browser console that those values are set correctly when I press the button to go to the next page.

The error:

pic of error code

The flow:

  1. Landing page is index.html with separate index.js
  2. Upon selection of a few drop-downs, 3 values are stored in sessionStorage
  3. Next page is called: normal-quiz.html with separate normal-quiz.js
  4. Values from sessionStorage are retrieved to filter a data array
  5. The loadQuiz function runs on the filtered array and sets a question element value to an object's 'english' property
  6. On first page load, only in Chrome on desktop, the above error occurs which makes the browser return to index.html and sessionStorage is cleared
  7. If I try the above again, it works without a problem

The line generating the error is where I use the loadQuiz function to set the question element's value in my html to the 'english' property value of the first object in the filtered array.

The code (js):

function redirect() {
if (selectedBook !== null) {
    // do nothing
} else {
    window.location = "<myURL>"
};
};

redirect();

function loadQuiz() {
const currentQuizData = quizArr[currentQuiz]; // currentQuiz is the question counter. It starts at 0 to get the first object, then increments by 1 after each question

questionEl.innerText = currentQuizData.english;
// line above is where the error is generated

counter.innerText = (currentQuiz + 1) + "/" + quizArr.length;
};
loadQuiz();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文