3
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

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

  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は爆発しろ。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
3
Help us understand the problem. What are the problem?