SSLサイトのJavaScriptに特定の文字列があると、IE8で「セキュリティで保護された…」の警告が出る(解決)

結論:Javascriptソース中のjavascript:void(0)を削除する(置き換える)


「セキュリティで保護されたwebページコンテンツのみ表示しますか」というセキュリティ警告は、通常はhttpsSSL)のページでhttp(非SSL通信)でファイルが読み込まれていると表示されるもの。
この警告に関しては、クライアント側のブラウザで表示しない設定にする記事はたくさん存在するものの(例)、サイト制作側の情報は少ない。


今回のケースは

  • 発生した環境はWindowsXP・InternetExplorer8
  • 全てのファイルがSSLで読み込まれている(参考:Firebugで調べる方法
  • CSSやJSの中まで確認した
  • 404になっているファイルは無し(参考)など
  • 同じマシンでも違うブラウザでアクセスすると警告は出ない
  • Windows7IE9という別の環境でアクセスしても警告は出ない

これはブラウザ(IE8)のバグではないか?類似したケースとして、IE6とiframeの組み合わせで同様のエラーが出るバグがある(参考)。しかし今回のケースには当てはまらない。


ググると、『HttpWatch』というデベロッパーツールの開発ブログに情報があった。(Even more problems with the IE 8 mixed content warning | HttpWatch Blog
この記事では

document.write("<script id="__ie_onload" src="javascript:void(0)"></script>");
document.getElementById("__ie_onload").onreadystatechange = function()
{
     if (this.readyState == "complete") domReady();
};

という部分を

document.write("<script id="__ie_onload" src="//:"></script>");
document.getElementById("__ie_onload").onreadystatechange = function()
{
     if (this.readyState == "complete") domReady();
};

としたらエラーが出なくなったとある。
ポイントは1行目で、

document.write("<script id="__ie_onload" src="javascript:void(0)"></script>");

この部分が原因のようだ。ここを "javascript:void(0)" から "//:" に書き換えたら警告が出なくなったとか。
素人なのでよく分からないが、javascript:void(0) というのはIEでDOMContentLoadedイベントを動かすためのテクニックらしい(直訳)。


MSDNのブログにも同様の記事があった。

Another common problem (described by lots of folks in the comments) is caused by using JavaScript protocol links for the SRC attribute of SCRIPT tags. In IE8 and below, the following SCRIPT tag will cause a mixed-content warning:

<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)">

If you simply remove the SRC attribute from this tag (since it's not performing a download), you will find the problem goes away.

Handling Mixed(HTTPS/HTTPS)Content - IEInternals - Site Home - MSDN Blogs


DojoというJSライブラリーのBugTrackにも。

The problem is simply the reference to "javascript:void(0)", which IE (for some stupid reason) feels is insecure.

#1342 (new dojo not working with SSL in IE) – Dojo Toolkit


こちらはlightboxで起きた例。
lightboxがSSLで警告 - アークウェブシステム開発SandBox


さて自分のケースでは、いくつか使用していたJavaScriptのうち、kamome.js という、スライドショーに使っていたスクリプトの398行目に javascript:void(0) があった。早速そこを //: に替えたところ、見事警告は出なくなったのでした。めでたしめでたし(JSの挙動がおかしくなっても知らない)