Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
528 views
in Technique[技术] by (71.8m points)

javascript - 页面完全加载后如何执行功能?(How to execute a function when page has fully loaded?)

I need to execute some JavaScript code when the page has fully loaded.(页面完全加载后,我需要执行一些JavaScript代码。)

This includes things like images.(这包括图像之类的东西。)

I know you can check if the DOM is ready, but I don't know if this is the same as when the page is fully loaded.(我知道您可以检查DOM是否准备就绪,但是我不知道这是否与页面完全加载时相同。)

  ask by Ben Shelock translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

That's called load .(这就是所谓的load 。)

It came waaaaay before DOM ready was around, and DOM ready was actually created for the exact reason that load waited on images.(在DOM准备就绪之前就已经出现了问题,实际上是由于等待图像load的确切原因而创建了DOM ready。)
window.addEventListener('load', function () {
  alert("It's loaded!")
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...