Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
3
Help us understand the problem. What is going on with this article?
@tsukaguitar

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

More than 5 years have passed since last update.
  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は爆発しろ。

3
Help us understand the problem. What is going on with this article?
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

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
3
Help us understand the problem. What is going on with this article?