2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

google-code-prettifyで、onloadじゃない関数の呼び出し方

Posted at
  1. シンタックスハイライトにgoogle-code-prettifyを使う際、onloadじゃちょっとアレかなー
  2. README読んだらaddEventListenerの方法あった
  3. あれ?古いIEはaddEventListenerだめじゃね?

という訳で、古いIEもいけるようにattachEvent版も併記したものをメモ。

読み込ませるファイル

<link rel="stylesheet" href="google-code-prettify/prettify.css">
<script src="google-code-prettify/prettify.js"></script>

関数呼び出し

<script>
//<![CDATA[
(function() {
  if(window.addEventListener) {
    window.addEventListener('load', prettyPrint, false);
  }
  else if(window.attachEvent) {
    window.attachEvent('onload', prettyPrint);
  }
})();
//]]>
</script>

これでOK…かな?IE8はチェック済み。

Google先生にも華麗にスルーされるオールドIE。ver.8未満のIEは爆発しろ。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?