Как запустить “onload” событие в документ в IE

Когда Вы принимаете решение во время компиляции по Компилятору/ОС/Аппаратным средствам определенное поведение.

Это позволяет Вам делать свой интерфейс к Comppiler/OS/Hardware определенным функциям.

#if defined(MY_OS1) && defined(MY_HARDWARE1)
#define   MY_ACTION(a,b,c)      doSothing_OS1HW1(a,b,c);}
#elif define(MY_OS1) && defined(MY_HARDWARE2)
#define   MY_ACTION(a,b,c)      doSomthing_OS1HW2(a,b,c);}
#elif define(MY_SUPER_OS)
          /* On this hardware it is a null operation */
#define   MY_ACTION(a,b,c)
#else
#error  "PLEASE DEFINE MY_ACTION() for this Compiler/OS/HArdware configuration"
#endif
7
задан Eric Bréchemier 9 December 2009 в 16:50
поделиться

3 ответа

Согласно этой странице в MSDN , нет события onload для документа .

Вы хотите либо ] window.onload или document.body.onload . Они идентичны в IE: по историческим причинам фактически устанавливает window.onload , поэтому MS решила создать document.body. onload псевдоним window.onload .

Проблема в том, как Эрик упомянул в комментариях, что, похоже, нет способа вручную запускать события окна, которые означает, что у проблемы Эрика может не быть решения.

4
ответ дан 7 December 2019 в 05:24
поделиться

For some reason, it appears that IE overrides the onload property of window with an empty object after the DOM is loaded. At least that is the case when you try to access it from within any event handler of a DOM element...

<!DOCTYPE html>
<html>
  <head>
    <title>Test by Josh</title>
    <script type="text/javascript">
      window.onload = function() {
        alert("Test");
      }
      alert(typeof window.onload);
    </script>
  </head>
  <body>
    <h1 onclick="alert(typeof window.onload);">Test</h1>
  </body>
</html>

In this situation, you'll see that window.onload is recognized as a function initially, then you see the "Test" alert. When you click on the heading, you'll see that window.onload is now an object. I tried iterating through the properties of the object, but it's empty. This is not cool.

One lame workaround is to grab the function in the accessible scope and assign it to a different property that you can fire at your convenience...

<!DOCTYPE html>
<html>
  <head>
    <title>Test by Josh</title>
    <script type="text/javascript">
      window.onload = function() {
        alert("Test");
      }         
    </script>
  </head>
  <body>
    <h1 onclick="window.onloadfix()">Test</h1>
    <!-- Could potentially be injected via server-side include if needed -->
    <script type="text/javascript">
      window.onloadfix = function() {
        window.onload();
      }
    </script>
  </body>
</html>

I can't think of any other way to address this issue right now.

4
ответ дан 7 December 2019 в 05:24
поделиться

Событие загрузки сработает, когда документ (включая внешние ресурсы, такие как изображения) будет полностью загружен, а не раньше.

Какие результаты вы получаете от своих попыток запустить readystatechange ? Действительно ли значение readyState вообще изменяется? Независимо от того, это тоже бесполезно: либо вы запускаете событие с readyState , которое не изменилось, либо вы делаете это с readyState , которое не является допустимым отражение состояния документа.

0
ответ дан 7 December 2019 в 05:24
поделиться
Другие вопросы по тегам:

Похожие вопросы: