简体   繁体   English

DOMContentLoaded 不会在 IOS Safari 上触发

[英]DOMContentLoaded does not fire on IOS Safari

First of all: I'm new to coding in generel.首先:我是一般编码的新手。 i just started 3 months ago.我刚开始3个月前。

I'm setting up a website for a friend.我正在为朋友建立一个网站。 The navbar of it should responsevely change it's html content what works fine on every device i tested.它的导航栏应该响应地改变它的 html 内容,在我测试的每台设备上都可以正常工作。 but when i try to set the innerHtml of my nav-ul with DOMContentLoaded, something goes wrong but only on the IOS Safari.但是当我尝试使用 DOMContentLoaded 设置我的 nav-ul 的 innerHtml 时,出现问题但仅在 IOS Safari 上。 unfortunately i can't use any browser developer tools on my ios safari.不幸的是,我不能在我的 ios safari 上使用任何浏览器开发工具。

Here is my app.js这是我的 app.js

document.addEventListener("DOMContentLoaded", function() {
const rect = document.querySelector(".main-container");
const screenWidth = rect.getBoundingClientRect().width;

if (screenWidth <= 800) {
    document.getElementById("navbar-list").innerHTML = `<li><a href="tel:xxxxx"><img src="./vector/phone1.png" alt="" class="icon"><p id="number">Anrufen</p></a></li><li><a href="whatsapp://send?text=Hallo! ich bin ein text der in einem whatsapp button programmiert ist auf peters website!&phone=xxxxx"><img src="./vector/icons8-whatsapp.svg" alt="" class="icon"><p>WhatsApp</p></a></li>`
} else {
    document.getElementById("navbar-list").innerHTML = `<li><a href="#home">Home</a></li><li><a href="#faecher">Fächer</a></li><li><a href="#konzept">Konzept</a></li><li><a href="#reviews">Ergebnisse</a></li><li><a href="#contact">Kontakt</a></li>`
}
});

Do i miss some await-stuff because i have to mention some async stuff?我是否错过了一些等待的东西,因为我不得不提到一些异步的东西?

Thanks for your help!谢谢你的帮助!

Can you log document.readyState inside of that callback?您可以在该回调中记录document.readyState吗? If it's not loading that means the event fired before the event listener was registered.如果它没有loading ,则意味着在注册事件侦听器之前触发了事件。

More here: https://developer.apple.com/forums/thread/651215更多信息: https://developer.apple.com/forums/thread/651215

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

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