誰でもこのスクリプトを手伝ってもらえますか?送信ボタンが付いたテキストボックスが必要です。特定のIDが入力されたら、特定のサイトにリダイレクトする必要があります(スクリプトの例はyahoo、bingなどです)。javascriptがURLリダイレクトで機能しない
以下はこれまでの内容ですが、送信ボタンは表示されず、送信ボタンが押されてもスクリプトを実行していないようです。
私はちょうど#を得る? URLに追加されました...私はopencartで働いていますので、問題の一部はopencartであると思います。
<html>
<head>
<script>
document.getElementById("gobutton").addEventListener("click", function(event){
event.preventDefault()
var idmap={
REDDIT:"http://reddit.com",
YAHOO:"http://yahoo.com",
BING:"http://bing.com"
};
id=document.getElementById("siteid").value;
if (id in idmap) {
alert("going to "+idmap[id]);
window.location.href=idmap[id];
} else {
alert("invalid code ["+id+"]")
}
event.preventDefault()
});
</Script>
</Head>
<Body>
<form id="urllauncher" action='#'>
<label for="siteid">Site id</label>
<input type="text" id="siteid">
<button type="submit" id="gobutton">Go</button>
</form>
</Body>
</Html>
ありがとうございました!
'window.location.href = idmap [id];' 'window.location = idmap [id];'を使用します。 – animaacija