• 締切済み

プルダウンから別ウィンドウを開く方法

プルダウンから別ウィンドウを開く方法 jsで管理しているプルダウンメニューの一部を 別ウィンドウで表示させたいのです。 下記の000.htmlをblankで表示させたい場合 どのような記述になるのでしょうか? どうぞよろしくお願いします。 function launch_report(obj) { var location = obj.options[obj.selectedIndex].value; if (location) { top.document.location.href = location; } } function shouhin() { document.open(); document.write("<select name=\"hoge\" size=\"1\" class=\"form\" onChange=\"launch_report\(this\)\">"); document.write("<option value=\"000.html\">メニュー"); document.write("</select>"); document.close(); }

みんなの回答

  • yamada_g
  • ベストアンサー率68% (258/374)
回答No.3

No.1さんのおっしゃるように条件分岐してwindow.openを使えばいいのでは? if(location === "000.html") { window.open(location); //その他オプションはご自由に } else { top.document.location.href = location; } みたいな感じで。

  • fujillin
  • ベストアンサー率61% (1594/2576)
回答No.2

リンク要素ならtargetを指定する方法もありそうですが、selectから開いているので、No1様のおっしゃるようにwindow.openを利用するのが一番簡単なのでは? ご提示のソース限定で。 function launch_report(obj) { var location = obj.options[obj.selectedIndex].value; if (obj.selectedIndex) { top.document.location.href = location; } else { window.open(location, "_blank"); } } でも、最初のオプションをどうやって選択するのだろうか?

  • pnck
  • ベストアンサー率90% (9/10)
回答No.1

html部分がないので試していませんが、 location.hrefではなく、window.openを使ってはどうでしょうか? window.open(location,'','');

googoogo0
質問者

補足

早速回答いただきありがとうございます! ただ、別ウィンドウで表示させたいのは、000.htmlのみなのです。。 質問の仕方が下手で申し訳ありません。 ↓のような感じで、全てが同ウィンドウで開くように 現在設定していますが、 000.htmlのみ別ウィンドウで開くようにリンクさせたいのです。 何度もすみませんが、ご回答をお待ちしています。 function launch_report(obj) { var location = obj.options[obj.selectedIndex].value; if (location) { top.document.location.href = location; } } function shouhin() { document.open(); document.write("<select name=\"hoge\" size=\"1\" class=\"form\" onChange=\"launch_report\(this\)\">"); document.write("<option value=\"000.html\">メニュー"); document.write("<option value=\"002.html\">メニュー2"); document.write("<option value=\"003.html\">メニュー3"); document.write("</select>"); document.close(); }

関連するQ&A

  • プルダウンから飛んだページを別ウインドウで開く方法

    初歩的なJavaScriptで申し訳ないのですが、ご教授願いします。 下記のプルダウンのJavaScriptで、例えばヤフーと言う部分を選択し、飛ぶをクリックするとヤフーに飛びますが、その際ヤフーにとんだページを別ウインドウで表示させたいのですが、お分かりの方いらっしゃいましたらこの素人に教えてください・・ <HTML> <HEAD> <script language="javascript"> <!-- function navi(obj) { url = obj.options[obj.selectedIndex].value; if(url != "") { location.href = url; } } //--> </script> </HEAD> <BODY> <form method=post> <select name="navi" size="10" "abc" onChange="document.b.submit()"> <option value="http://www.yahoo.co.jp/">ヤフー </select> <input type=button value="飛ぶ" onClick="location.href = this.form.navi.options[this.form.navi.selectedIndex].value"> </form> </BODY> </HTML>

  • プルダウンメニューを中央に置きたい 

    HPB15 プルダウンメニューを中央に置きたいのです。 同じやり方で作成していますが、右側の公共機関 は中央にあります。 どうすれば 中央にできますか http://www006.upp.so-net.ne.jp/*******/********/index.html ---------------------------------------------------------- <!-- function jumpURL(target){ if(target != ""){ location.href = target } } document.write('<FORM>') document.write('<SELECT NAME="select" onChange="jumpURL(this.options[this.selectedIndex].value)">') document.write('<OPTION VALUE="">*****); document.write('<OPTION VALUE="../********/etc/aisatu.html">会長挨拶'); document.write('<OPTION VALUE="../********/etc/yakuin.html">役員名簿'); document.write('<OPTION VALUE="../********/etc/jigyoukeikaku.html">事業計画'); document.write('<OPTION VALUE="../********/H22katsudou.html">活動報告'); document.write('<OPTION VALUE="../********/H22kiyaku1.html">規約'); document.write('<OPTION VALUE="../********/etc/chiikizu.html">宮谷地域図'); document.write('<OPTION VALUE="../********/etc/heimenzu.html">会館平面図'); document.write('</SELECT></FORM>') //--> よろしくお願いします。

    • ベストアンサー
    • CSS
  • 複数プルダウンでメニューを初期表示に戻したい

    No.157334でleaz024さんに「複数プルダウンメニュー」について教えてもらったものですが、ひとつ、追加したいことがあるので教えてください。 教えていただいたスクリプトは <script language="javascript"> <!-- function A_Li() {   Sel=document.Link1.OP.selectedIndex;   Ms=document.Link1.OP.options[Sel].value;   parent.main.location.href=Ms;} function B_Li() {   Sel=document.Link1.OP2.selectedIndex;   Ms=document.Link1.OP2.options[Sel].value;   parent.main.location.href=Ms;} // --> </script> <FORM name="Link1"> <SELECT name="OP" onChange="A_Li()" size="1"> <OPTION Value="main.htm" SELECTED>ページを選んでください <option value="main.htm">ぺージ1</option> <OPTION Value="abc.htm">ページ2 <OPTION Value="def.htm">ページ3 </SELECT> <SELECT name="OP2" onChange="B_Li()" size="1"> <OPTION Value="aaa.htm" SELECTED>ページを選んでください <option value="bbb.htm">ぺージ1</option> <OPTION Value="ccc.htm">ページ2 <OPTION Value="ddd.htm">ページ3 </SELECT> です。 例えば OP2のメニューをクリックしたあと OP3のメニューをクリックしたときにOP2のメニューが初期の 表示メニューに戻したいのですが、どう変えればよいでしょうか。 初心者なので本を見てみたのですがわかりませんでした。 どうぞよろしくお願いいたします。

  • プルダウンメニューが文字化けする

    タイトル通りプルダウンメニューが文字化けしてしまいます。javaを使ってホームページに表示させています <meta http-equiv="Content-Type" content="text/html; charset=shift_jis"> <!--メニュー↓--> <script language="javascript"> <!-- function navi(obj) { url = obj.options[obj.selectedIndex].value; if(url != "") { location.href = url; } } //--> </script> <form method=post> <select name="navi">  <option value=""> --メニュー -- <option value="http://">TOPページ <option value="http://">特別企画 <option value="http://">ご挨拶 <option value="http://">ご協力 <option value="http://">PC版 <option value="http://">ブログ </select> <input type=button value="ジャンプ" onClick="location.href = this.form.navi.options[this.form.navi.selectedIndex].value"> </form> <!--メニュー↑-->

  • プルダウンメニューのリンクで別ウインドウを開く

    下記のようなプルダウンメニューを作成したのですが、同じウインドウ内でリンクするのではなく別ウインドウで開くようにするにはどこを変更すればよいのでしょうか? head内>>>>>>>>>>>>> <script language="JavaScript" type="text/JavaScript"> <!-- function gotoURL(formName){ var gotoUrl=document.forms[formName].elements[0].options[document.forms[formName].elements[0].selectedIndex].value document.location.href=gotoUrl } --> </script> body内>>>>>>>>>>>>>> <form name="fm0"> <select name="links"> <option selected><ここから選択してください></option> <option value="aaa.html">あああ</option> <option value="bbb.html">びびび</option> </select> <input name="BUTTON" TYPE=BUTTON onClick="gotoURL('fm0')" VALUE="GO!"></form>

  • プルダウンメニューがIEだとエラー

    買い物かごをプルダウンメニューで作ったのですが、firefoxではちゃんと次のページ(かごに入れて、かごの中身を表示)に行くのに、IEだと、ちゃんとかごに入りません(ショッピングカートに入れられない、とエラーが出る)何故でしょうか? このタグを打っているのですが(タグ紹介のページでコピった)、間違っていますか? <script language="javascript"> <!-- function goToUrl(obj) { url = obj.options[obj.selectedIndex].value; if(url != "") { location.href = url;} } //--> </script> <form method="post"> <select onChange="goToUrl(this)"> <option value="">▽選択してください <option value="http://~">○○ <option value="http://~" >××</select> </form>

    • ベストアンサー
    • HTML
  • プルダウンで選択したページから戻った時

    どなたか教えてください。 プルダウンで選択したページにリンクして、そのページから戻ってきた場合、 プルダウンメニューは選択した項目ではなく、一番上に来る項目が選択されているようにしたいのです。 例:--メニュー--    テスト1ページへ    テスト2ページへ ↓をやったら、うまくいったのですがステータスバーに「1」と表示されてしまいました。 <script language="JavaScript"> <!--// function gotosite(site) { if (site != "") { self.location=site } } function init() { status = document.jump.length; for (i=0; i<document.jump.length; i++) document.jump.elements[i].selectedIndex=0; } //--> </script> ちなみにselectのところはこのように書きました。 <form method="POST" name="jump"> <select name="jump" onChange="gotosite(this.options [this.selectedIndex].value)"> よろしくお願いします。どうしても「1」を出したくないんです。 やっぱり無理なんでしょうか?

  • 複数のプルダウンメニューの選択項目を変更するには?

    複数のプルダウンメニューを使ってページリンクをさせています。 その際ページリンクと同時に、他のメニューの選択項目を初期値す方法を教えてください。 No.157334で同じような質問があったので、それを参考に以下のように記述してみましたが、 function reSel(c) { for(i=0; i<9; i++){ var s="document.unit.DDList"; var x=s+i; if(x != c){ x.selectedIndex=0; //ココがうまくいきません。 } } } function Li_0(obj){ parent.res.location.href=obj.options[obj.selectedIndex].value; reSel("document.unit.DDList0"); } (以降 Li_8まで同様) <form name="unit" method="post"> <select name="DDList0" size="1" onChange="Li_0(this)"> <option value="help.html" selected> </option> <option value="unit_a.html">AAA</option> <option value="unit_b.html">BBB</option> </select> (以降 DDList8まで同様) です。 どうぞよろしくお願いいたします。

  • 複数のプルダウンメニューの表示について

    複数のプルダウンメニューについてですが、 以前、こちらで教えてもらったことを応用したいのです。 フォーームの中の「グループ1」と「グループ2」という大分類は文字の表示だけでリンクしないようにしたいのです。 この状態だと、「グループ1」という名前もプルダウンの中に入ってしまって、 ファイルがないので、リンクエラーの警告がでます。 どこが間違っていて、 どのように変えたらいいのでしょうか。 よろしくお願い致します。 <script language="javascript"> <!-- var s; function reSel(c) { if(s&&(s!=c)) s.options[0].selected=true; s=c; } function A_Li() {   Sel=document.Link1.OP.selectedIndex;   Ms=document.Link1.OP.options[Sel].value;   parent.main.location.href=Ms; reSel(document.Link1.OP); } function B_Li() {   Sel=document.Link1.OP2.selectedIndex;   Ms=document.Link1.OP2.options[Sel].value;   parent.main.location.href=Ms; reSel(document.Link1.OP2); } // --> </script> ---------------HTML------------ <FORM name="Link1"> <SELECT name="OP" onChange="A_Li()" size="1"> <OPTION Value="-" SELECTED>グールプ1</option> <option value="1.htm">あ</option> <OPTION Value="2.htm">い</option> <OPTION Value="3.htm">う</option> <OPTION Value="4.htm">え</option> <OPTION Value="5.htm">お</option> </SELECT> <SELECT name="OP2" onChange="B_Li()" size="1"> <OPTION Value="-" SELECTED>グールプ2</option> <option value="6.htm">か</option> <OPTION Value="7.htm">き </option> <OPTION Value="8.htm">く </option> </SELECT>

  • プルダウンメニューリンクを新しいウインドウで表示させたい

    ホームページビルダー11を使っています。プルダウンメニューからリンク先を「新しいウインドウ」で表示させるにはどのようにしたらよろしいのでしょうか。ご指導よろしくお願い致します <SCRIPT language="JavaScript"> <!--- 非表示 function quicklink(w){ if(w == "") return; document.quick.url.selectedIndex = 0; location.href =w; } //end ---> </SCRIPT> <FORM name="quick" action="./"><SELECT name="url" onchange="quicklink(this.form.url.options[this.form.url.selectedIndex].value)" size="1" tabindex="1"> <OPTION selected>■ リンク先を選んでクリック ■ </OPTION> <OPTION value="index.htm">その1</OPTION> <OPTION value="index-2.htm">その2</OPTION> <OPTION value="index-3.htm">その3</OPTION> </SELECT>←関連リンク先</FORM> <TABLE width="100%" border="1" cellpadding="0" cellspacing="0" class="hpb-subh02">