codeconv_f13.htm

戻る

<!DOCTYPE HTML>
<HTML LANG="ja">

<HEAD>
<META CHARSET="Shift_JIS">
<TITLE>文字コード変換</TITLE>
</HEAD>

<BODY STYLE="background-color:#CCFFFF">
<CENTER>
<B>文字コード変換 (Firefox 13)</B>
<BR><BR>

<FORM ID="form" ACTION="data:," TARGET="target">
<TABLE>
<TR><TD NOWRAP>
入力文字コード:
<INPUT TYPE=TEXT ID="i_enc" SIZE=30>
<SPAN STYLE="position:relative">
<INPUT TYPE=BUTTON VALUE="選択" onClick="sel_opt(this, elem_i_enc)" STYLE="position:relative">
</SPAN>
<INPUT TYPE=BUTTON ID="in" VALUE="読み込み" onClick="input()" STYLE="margin-left:1em">
</TD></TR>
<TR><TD NOWRAP>
出力文字コード:
<INPUT TYPE=TEXT ID="o_enc" SIZE=30>
<SPAN STYLE="position:relative">
<INPUT TYPE=BUTTON VALUE="選択" onClick="sel_opt(this, elem_o_enc)" STYLE="position:relative">
</SPAN>
<SPAN STYLE="margin-left:1em">改行:</SPAN>
<SELECT ID="le">
<OPTION>LF
<OPTION>CR
<OPTION>CR+LF
</SELECT>
<INPUT TYPE=BUTTON ID="out" VALUE="書き出し" onClick="output()" STYLE="margin-left:1em">
</TD></TR>
<TR><TD>
<TEXTAREA NAME="d" ID="data" ROWS=20 COLS=80 WRAP="OFF"></TEXTAREA>
</TD></TR>
</TABLE>

<SPAN ID="clip" STYLE="position:absolute; left:0; top:0; z-index:1; border:solid thin gray; visibility:hidden">
<SELECT ID="opt" SIZE=5 STYLE="border:none">
<OPTION>ISO-8859-1
<OPTION>ISO-2022-JP
<OPTION>Shift_JIS
<OPTION>EUC-JP
<OPTION>UTF-8
</SELECT>
</SPAN>
</FORM>

</CENTER>

<IFRAME NAME="target" ID="frame" WIDTH=1 HEIGHT=1 SRC="about:blank" STYLE="display:none"></IFRAME>
<A ID="dl" STYLE="display:none"></A>

<SCRIPT TYPE="text/javascript">
<!--

function sel_opt(sel, enc) {
  elem_sel = sel;
  elem_enc = enc;
  elem_opt.selectedIndex = 0;
  elem_sel.parentNode.appendChild(elem_clip);
  elem_clip.style.display = "inline-block";
  elem_opt.focus();
}

function opt_click() {
  elem_enc.value = elem_opt.value;
  elem_clip.style.display = "none";
}

function opt_keydown(e) {
  switch(e.keyCode) {
  case 9:  // Tab
    if(e.shiftKey) {
      elem_enc.focus();
      e.preventDefault();
    }
    break;

  case 13:  // Enter
    elem_enc.value = elem_opt.value;
    // fall thru
  case 27:  // Esc
    elem_clip.style.display = "none";
    break;
  }
}

function opt_blur() {
  elem_clip.style.display = "none";
}

// 読み込み
function input() {
  elem_in.disabled = elem_out.disabled = true;
  setTimeout(enable_btn, 100);
  // ファイルを開く
  elem_file = document.createElement("INPUT");
  elem_file.type = "FILE";
  elem_file.onchange = input2;
  elem_file.click();
}

function enable_btn() {
  elem_in.disabled = elem_out.disabled = false;
}

function input2() {
  elem_in.disabled = elem_out.disabled = true;
  // フレームにレンダリングする
  elem_frame.onload = input3;
  elem_frame.src = URL.createObjectURL(
    // 取得した File に MIME タイプを付加した Blob を作る
    new Blob([elem_file.files.item(0)], {type: "text/plain;charset=" + elem_i_enc.value.trim()}));
}

function input3() {
  elem_frame.onload = null;
  // フレームから変換結果を取り出す
  elem_data.value = elem_frame.contentDocument.body.textContent;
  elem_in.disabled = elem_out.disabled = false;
}

// 書き出し
function output() {
  elem_in.disabled = elem_out.disabled = true;
  // フォームの文字エンコーディングをセットして送信
  elem_form.acceptCharset = elem_o_enc.value.trim();
  elem_frame.onload = output2;
  elem_form.submit();
}

function output2() {
  elem_frame.onload = null;
  // フレームから URL を取り出す
  var str = elem_frame.contentDocument.location.href;
  str = str.substring(str.indexOf("?") + 3).replace(/\+/g, "%20");  // ?d= の後ろを取り出し,スペースを %20 に変換
  switch(elem_le.selectedIndex) {  // 改行
  case 0:  // LF
    str = str.replace(/%0[Dd]/g, "");
    break;
  case 1:  // CR
    str = str.replace(/%0[Aa]/g, "");
    break;
  }
  // 変換結果をダウンロードする
  elem_dl.href = "data:application/octet-stream," + str;
  elem_dl.click();
  elem_in.disabled = elem_out.disabled = false;
}

  elem_form = document.getElementById("form");
  elem_i_enc = document.getElementById("i_enc");
  elem_in = document.getElementById("in");
  elem_o_enc = document.getElementById("o_enc");
  elem_le = document.getElementById("le");
  elem_out = document.getElementById("out");
  elem_data = document.getElementById("data");
  elem_clip = document.getElementById("clip");
  elem_opt = document.getElementById("opt");
  elem_frame = document.getElementById("frame");
  elem_dl = document.getElementById("dl");

  with(elem_clip.style) {
    width = String(elem_clip.offsetWidth - (elem_opt.offsetWidth - elem_opt.clientWidth)) + "px";
    display = "none";
    overflow = "hidden";
    visibility = "";
  }

  elem_opt.onclick = opt_click;
  elem_opt.onkeydown = opt_keydown;
  elem_opt.onblur = opt_blur;

  // ページを再ロードしたときのため
  elem_form.reset();
  elem_in.disabled = elem_out.disabled = false;

//-->
</SCRIPT>

</BODY>

</HTML>