[ JavaScript ] 現在のページをエキサイト翻訳にリンクするサンプル

サンプルコード ———————————————————————-

index.html

<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>エキサイト翻訳にリンクするサンプル</title>
<script type="text/javascript" src="test.js"></script>
</head>
<body>
<p><a href="javascript:test1();">エキサイトの英語翻訳にリンク。別ウインドウで開きます。</a></p>
<p><a href="javascript:test2();">エキサイトの韓国語翻訳にリンク。別ウインドウで開きます。</a></p>
<p>試験用の日本語です。</p>
</body>

test.js

function test1() {
  var add1 = ‘http://www.excite.co.jp/world/english/web/?wb_url=’;
  var add2 = encodeURIComponent(location.href);
  var add3 = ‘&amp;wb_lp=JAEN&amp;wb_dis=2’
  window.open(add1 + add2 + add3)
}
function test2() {
  var add1 = ‘http://www.excite.co.jp/world/korean/web/?wb_url=’;
  var add2 = encodeURIComponent(location.href);
  var add3 = ‘&amp;wb_lp=JAKO&amp;wb_dis=2’
  window.open(add1 + add2 + add3)
}

実際に動作するサンプル ———————————————————————-

エキサイト翻訳にリンクするサンプル

動作を確認したウェブブラウザ

– OK – Mac Firefox 2.0 – OK – Mac Safari 2.0 – OK – Windows Firefox 2.0 – OK – Windows Internet Explorer 7.0

その他

– ブックマークレットもできるんじゃね? – 翻訳元ファイルの文字コードは Shift_JIS が良さげ。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です