HTMLのIFRAMEについて教えて

このQ&Aのポイント
  • HTMLのIFRAMEを使って、特定の数字に応じて写真を表示する方法について教えてください。
  • 現在、数字によってIFRAME内に表示される写真を変えるためのスクリプトがエラーになっています。どのように修正すればよいでしょうか。
  • 他の方法でも結構ですが、数字を入力するとIFRAME内に対応する写真が表示される方法について教えてください。
回答を見る
  • ベストアンサー

HTMLのIFRAMEについて教えて

HTMLのIFRAMEについて教えて欲しいのですが、 例えば、cgiの入力項目で、数字の1を入力した場合、aaa.htmlというページ内にあるIFRAMEで囲まれた エリア内に、1の写真が表示できるようにしたいのです。 現在、以下のような記述をしているのですが、IFRAMEの部分がエラーになってしまうのです。(>_<) noには、数字の変数が入っています。 他の方法でも結構なのですが、数字によってIFRAME内に表示される写真を変えたいのです。 どなたか、宜しくおねがいします。 <script type="text/javascript"> <!-- switch(no){ case 0: id = "01.jpg"; break; case 1: id = "02.jpg"; break; case 2: id = "03.jpg"; break; default : id = "00.jpg"; break; } // --> </script> <iframe src="id" name="picture" width="300" height="300"></iframe>

  • HTML
  • 回答数2
  • ありがとう数0

質問者が選んだベストアンサー

  • ベストアンサー
  • yyr446
  • ベストアンサー率65% (870/1330)
回答No.1

これってcgiで出力するhtmlの話ですか?それとも単なるDOM操作ですか? 後者なら <iframe id="target" src="id" name="picture" width="300" height="300"></iframe> としておいて、 switch(no){ case 0: id = "01.jpg"; break; case 1: id = "02.jpg"; break; case 2: id = "03.jpg"; break; default : id = "00.jpg"; break; } document.getElementById("target").setAttribute("src",id); でセットするだけです。

その他の回答 (1)

  • LOHA
  • ベストアンサー率52% (203/388)
回答No.2

画像を表示するだけなのでしたら、どうせJavascriptを使うならiframeなどつかわずに普通にimgをDOM操作するのがスマートだと思いますよ。 ちなみに本当にCGIを使っているのでしたら、iframeを使う必要もないし、Javascriptも必要ないと思います。 # おそらくCGIの意味を取り違えているだけで、CGIは関係ないと思われますが

uoorurun
質問者

補足

はい、皆様のアドバイス通り、cgiは一例でございまして、 現在は、ソースファイルで「switch」文の前に「1」や「2」といった数字を入れて実験をしている状態です。 iframe文の、「src」に「id」と入れると、「no」が「1」の時に、「02.jpg」が入らないので困っております。 初心者なのですみません。

関連するQ&A

  • <iframe>内にHTMLをランダム表示するには?

    かなりの素人なので説明不足などで分かりづらいところが多々あると思いますが、 何卒宜しくお願い致します。 同じhtmlに複数のiframeがあるのですが、 その全てのiframeをランダムにしたいのですが、 あまりの素人なので全く分かりません。 申し訳ありませんが、 多少いじってコピペするくらいまでのソースを教えて頂けますでしょうか? 宜しくお願い致します。 iframe一つだけのランダムは以下のソースでできました。 <head> <script type="text/javascript"> <!-- function RndmSubFlame(){ rlURL= new Array(); rlURL[0]="01.html" rlURL[1]="02.html" rlURL[2]="03.html" n=rlURL.length; x=Math.floor(Math.random()*n); sub_flame.location.href = rlURL[x]; } //--> </script> </head> <body TopMargin=0 LeftMargin=0 RightMargin=0 BottomMargin=0 STYLE="overflow:auto;height:100%;" onLoad="RndmOpen()"> <script><!-- document.write("<iframe src=\""+riURL[x]+"\"></iframe>"); //--> </body> 以下のhtmlのようなページです。 できましたら、このソースに書き加え頂けますと 大変助かります。 宜しくお願い致します。 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=shift_jis"> <title></title> </head> <body> <table border="1" width="84%" height="87"> <tr> <td width="33%" height="81"><iframe src="a01.html" frameborder="0" width="100%" height="190" name="01" scrolling="no"></iframe></td> <td width="33%" height="81"><iframe src="a01.html" frameborder="0" width="100%" height="190" name="02" scrolling="no"></iframe></td> <td width="34%" height="81"><iframe src="a01.html" frameborder="0" width="100%" height="190" name="03" scrolling="no"></iframe></td> </tr> </table> </body> </html>

  • <iframe>内にHTMLをランダム表示するには?続きです。

    先日の<iframe>内にHTMLをランダム表示するには?の続きなのですが、 http://questionbox.msn.co.jp/qa2962976.htmlの疑問は 皆様のお力で解決しました。 誠にありがとうございました。 もう一つ教えて頂きたいことがあるのですが、 かなりの素人なので説明不足など分かりづらいところが多々あると思いますが、 何卒宜しくお願い致します。 同じhtmlに複数のiframeを配置し、 各iframeをランダムにしたいのです。 その際、各iframeは別々のフォルダーに収納されているhtmlを 表示するようにしたいです。 例えば、同じhtmlに iframe1、iframe2、iframe3があるとし、 01、02、03という3つのフォルダーの中に 01.html、02.html、03.htmlがそれぞれ収納されているとした場合、 iframe1は01のフォルダーの中のhtmlをランダムで表示し、 iframe2は02のフォルダーの中のhtmlをランダムで、 iframe3は03のフォルダーの中のhtmlをランダムで、 といったランダム表示にしたいです。 あまりの素人なので全く分かりませんので、 大変申し訳ありませんが、 多少いじってコピペするくらいまで完成されたソースを教えて頂けますでしょうか? 宜しくお願い致します。 ------------------------------------------------------------------------- 以下のソースは、 3つのiframeに同じフォルダー内のhtmlをランダムで表示させることができたソースです。 教えてもらいました。 こちらは参考までに載せました。_ <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=shift_jis"> <title></title> <script type="text/javascript"> <!-- function RndmSubFlame(){ rlURL= new Array(); rlURL[0]="01.html" rlURL[1]="02.html" rlURL[2]="03.html" n=rlURL.length; x1=Math.floor(Math.random()*n); x2=Math.floor(Math.random()*n); x3=Math.floor(Math.random()*n); s01.location.href = rlURL[x1]; s02.location.href = rlURL[x2]; s03.location.href = rlURL[x3]; } //--> </script> </head> <body onload="RndmSubFlame()"> <table border="1" width="84%" height="87"> <tr> <td width="33%" height="81"><iframe src="a01.html" frameborder="0" width="100%" height="190" name="s01" scrolling="no"></iframe></td> <td width="33%" height="81"><iframe src="a01.html" frameborder="0" width="100%" height="190" name="s02" scrolling="no"></iframe></td> <td width="34%" height="81"><iframe src="a01.html" frameborder="0" width="100%" height="190" name="s03" scrolling="no"></iframe></td> </tr> </table> </body> </html> ------------------------------------------------------------------------- 以下のhtmlソースに書き加えてもらえると大変助かります。 何卒、宜しくお願い致します。 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=shift_jis"> <title></title> </head> <body> <table border="1" width="45%" height="448"> <tr> <td width="46%" height="210"><iframe src="01/01.html" frameborder="0" width="100%" height="190" name="01" scrolling="no"></iframe></td> <td width="54%" height="442" rowspan="2"><iframe src="03/01.html" frameborder="0" width="100%" height="190" name="03" scrolling="no"></iframe></td> </tr> <tr> <td width="46%" height="226"><iframe src="02/01.html" frameborder="0" width="100%" height="190" name="02" scrolling="no"></iframe></td> </tr> </table> </body> </html>

  • IFRAMEのscrollingを常にnoにしたい

    iframeを使ってBBSをscrolling="no"で表示したいのですが、 src="パスワード.cgi"から自動でbbs.cgiになったときにスクロール表示してしまいます。 iframe内で表示先が変更された場合でもスクロール表示しないようにできるのでしょうか?もしできるのであれば教えていただきたいのですが… 掲示板をiframe と言うことで、某ホームページをを参考にスクロールが表示さ れないようにしてみました。 が以下のようにパスワードを入力後に表示するiframe はスクロールを表示して しまいます。 <script type="text/javascript"> <!-- function LoadFrame(frid) { var IFR = document.getElementById(frid); IFR.style.height = (IFR.contentWindow)? IFR.contentWindow.document.body.scrollHeight: document.frames[frid].document.body.scrollHeight; } //--> </script> <iframe src="member/gate.cgi" name="coach" onload="LoadFrame(this.id)" id= "Ifr" width=497 frameborder="0" scrolling="no"></iframe> 試行錯誤しながらなんとかやってる超初心者です。よろしくお願いします。

  • iframeにリンクを貼る

    <iframe src="qqq.gif" height="150" width="356" align="left" frameborder="0" scrolling="no" marginheight="1" name="tv" > この部分はiframe表示です </iframe> にURLを指定してリンクを張りたいのですが、どうしたらいいですか?

  • 複数の<iframe>内にHTMLをランダム表示

    以下のようなソースで、ランダムにHTMLをIFRAMEに読み込むソースを書いています。 (Javascript) window.onload = function(){ var c = 23; //ランダムに表示するiframe内URLの数 var ifm = document.getElementById('aaa');//frameIDを入力 var r = Math.floor( Math.random() * c ); var urls = new Array(); urls[0] = '../text/1.html'; urls[1] = '../text/2.html'; urls[2] = '../text/3.html'; urls[3] = '../text/4.html'; urls[4] = '../text/5.html'; urls[5] = '../text/6.html'; urls[6] = '../text/7.html'; urls[7] = '../text/8.html'; urls[8] = '../text/9.html'; urls[9] = '../text/10.html'; ifm.src = urls[r]; } (HTML) <iframe src="#" id="aaa" frameborder="0" marginwidth="0" width="115" marginheight="0" scrolling="no"></iframe> このような要領で、 id="aaa"にはtextフォルダ内のファイル1.html~10.htmlのうちからランダムで、 id="bbb"にはtextフォルダ内のファイル11.html~20.htmlのうちからランダムで、 id="ccc"にはtextフォルダ内のファイル21.html~30.htmlのうちからランダムで、 ・・・・ といった感じで以下のようなソースでそれぞれ読み込めればと思っているのですが、どうやったら可能でしょうか? <iframe src="#" id="aaa" frameborder="0" marginwidth="0" width="115" marginheight="0" scrolling="no"></iframe> <iframe src="#" id="bbb" frameborder="0" marginwidth="0" width="115" marginheight="0" scrolling="no"></iframe> <iframe src="#" id="ccc" frameborder="0" marginwidth="0" width="115" marginheight="0" scrolling="no"></iframe> javascriptにかんしてはあまり詳しくありませんので、ちょっと改変してコピペするくらいまでのソースを教えていただけませんでしょうか? よろしくおねがいします。

  • iframeクッキー2

    すみません。解決したと思っていたのに後で確認したところ、出来ていませんでした。 一度削除したのに、またこうやって立てて、申し訳ないです。 何度も試行錯誤しましたがまったくうまくいかなかったので質問させて頂きます。 testページではできたのですが、index.htmlの方にするとうまくいきません。 タグをおいておきます。 ************************* index.htmlの基本とiframe ************************* <html> <head> <title></title> <META>(3行、METAタグをおいています) <link rel="stylesheet" type="text/css" href="/standard.css"> <script language="JavaScript" src="/standard.js"></script> <script> function GetHeightForIndex(){ GetHeight("iframeのID"); } </script> </head> <body onLoad="Clock(),Ref()"> <table ~~~ ~~~ <td valign=top width=87% rowspan=2> <script type="text/javascript"> var cook_key = "iframesrc"; /* クッキーのキーになる適当な名前 */ var cook_src; var cookies = document.cookie.split(';'); for(var i=0; i<cookies.length; i++){ if(cookies[i].indexOf(cook_key) >-1){ cook_src = cookies[i].split('='); break; } } var file = cook_src? cook_src[1] : 'a.htmlにあたるページアド'; (/inde.html なら、 /フォルダ名/a.html のファイルの位置にあります) document.write('<iframe class=tmain src="',file,'" id="iframeのid" name="iframeの名前" frameborder="0" scrolling="no" height="1500"></iframe>') function setCook(arg){ document.cookie = cook_key + '=' + arg + ';'; } </script> <noscript> <iframe class=tmain src=.htmlにあたるページアド id="iframeのid" name="iframeの名前" frameborder=0 scrolling=no height=1500></iframe> </noscript> </td></tr> </table> </body> </html> ************************* index.htmlのリンク ************************* <a href=c.htmlにあたるページ onclick="setCook(this.href)">掲示板</a> </td><td class=white width=1> <div id="line"></div> </td><td class=white><center> <a href=d.htmlにあたるページ onclick="setCook(this.href)">チャット</a> a.htmlはテーブルリンクを使用しています。 <table ~~~ <td onClick="tmain.location.href='a.htmlにあたるページ',setCook(this.href)" STYLE="cursor:hand;"> ************************* standard.js ************************* 時計や更新日、iframeの高さ可変など~~~ //iframeクッキー var cook_key = "iframesrc"; /* クッキーのキーになる適当な名前 */ window.onload = function(){ if(cook_src) document.getElementById('iframeのID').src = ''; var cook_src; var cookies = document.cookie.split(';'); for(var i=0; i<cookies.length; i++){ if(cookies[i].indexOf(cook_key) >-1){ cook_src = cookies[i].split('='); break; } } document.getElementById('iframeのID'').src = cook_src ? (cook_src[1] ? cook_src[1] : 'a.htmlにあたるページアド') : 'a.htmlにあたるページアド'; } function setCook(arg){ document.cookie = cook_key + '=' + arg + ';'; } こういう状態なのですがうまく機能されません。 この状態だと、 最初に表示されるa.html  × (表示されない。404になる。) b.thmlの表示と更新しても同じように表示される(クッキー有) ○ c.htmlやd.htmlなど、表示 ○  ↑の状態でを更新をおす。 ×  (a.htmlの最初に表示するときと同じように404) a.htmlのリンクを押す。(a.htmlが表示される) ○ document.write('<iframe class=tmain src="',file,'" id="iframeのid" name="iframeの名前" frameborder="0" scrolling="no" height="1500"></iframe>') の ',file,'の部分をa.htmlにあたるページに直すと、 最初に表示されるa.html、c.htmlとd.htmlを更新した際、共にa.htmlが正常に表示されたので、出来たのかと思ったのですが、 b.htmlで更新を押すと、クッキーが無になり、a.htmlが表示されるようになる。 何度もすみませんが、うまくいかず、困ったので教えてください。 P.S.  b.htmlのようなページを複数にする場合には、 リンクの onclick="setCook(this.href)" をb.htmlのようにしたいページのリンク(aタグ)に入れればいいですよね?

  • Iframeとして呼び出すページを120px以下を表示したい

    Iframeを使いたいのですが、A.htmlの高さ120pixから下をIframeで指定したいときはどうしたらいいでしょうか。 <html> <head> <title>testtitle> </head> <body> <div width:100%; height:120px;> <table> <tr> <td><iframe src="A.htm" width="100%" height="100%" frameborder="0" scrolling="no" overflow:no></iframe><td> </tr> </table> </div> </body> </html> 呼び出すIframeの中身のページについて 高さを120pix以下を表示したいのですが。 よろしくおねがします。

  • iframeクッキー あと少しで

    またしても立ててしまいました。 自分の力ではどうしようも出来ないので、立てたことお許しください。 index.htmlのiframeに最初に表示されているページ a.html index.htmlの<a>タグリンクでiframe内に表示するページの内、  クッキーによって、更新おしてもiframe内を変えないページ b.html・c.html  クッキーを解除し、更新を押すと、a.htmlを表示するページ d.html・e.html 現在、今までの質問で以下のタグでiframeのクッキーを使用しています。 ************************************************************************** index.html ************************************************************************** <head>内  <script language="JavaScript" src="/standard.js"></script>  <script><!--  function GetHeightForIndex(){  GetHeight("tmain");  }  //--></script>  これは、iframeの高さ可変のタグです <body>内  <a href="b.html" onclick="setCook(this.href)">b</a>  <a href="c.html" onclick="setCook(this.href)">c</a>  <a href="d.html" onclick="setCook('')">d</a>   <a href="e.html" onclick="setCook('')">e</a> <script type="text/javascript"><!-- var cook_key = "iframesrc"; if(cook_src) document.getElementById('iframe名').src = 'a.html'; var cook_src; var cookies = document.cookie.split(';'); for(var i=0; i<cookies.length; i++){ if(cookies[i].indexOf(cook_key) >-1){ cook_src = cookies[i].split('='); break; } } var file = cook_src? cook_src[1] : 'a.html'; document.write('<iframe class="tmain" src="',file,'" id="iframeID" name="iframe名" frameborder="0" scrolling="no" height="1500"></iframe>') document.getElementById('tmain').src = cook_src ? (cook_src[1] ? cook_src[1] : 'a.html') : 'a.html'; function setCook(arg){ document.cookie = cook_key + '=' + arg + ';'; } //--></script> <noscript> <iframe class="tmain" src="a.html" id="iframeId" name="iframe名" frameborder="0" scrolling="no" height="1500"></iframe> </noscript> ************************************************************************** standard.js ************************************************************************** //iframe高さ可変 function getIFrameDocument(aID){ if (document.getElementById(aID).contentDocument){ return document.getElementById(aID).contentDocument; } else { return document.frames[aID].document; } } function GetHeight(ID){ if (document.height) { document.getElementById(ID).style.height = getIFrameDocument(ID).height +20 +"px" ; }else{ document.getElementById(ID).style.height = getIFrameDocument(ID).body.scrollHeight +20 +"px"; } } //iframeクッキー var cook_key = "iframesrc"; window.onload = function(){ } function setCook(arg){ document.cookie = cook_key + '=' + arg + ';'; } user_pref("dom.disable_window_open_feature.scrollbars", true); ************************************************************************** この状態で現在、困っているのは  a.htmlを表示している状態で更新を押すと、iframe内が404になることです。 b.htmlなどで更新を押すと、b.htmlが表示されたままだし、 d.htmlなどで更新を押すと、a.htmlが表示されます。 解決方法教えてくださいっ。

  • <iframe>内をリロードするたびに入れ替えたい

    <iframe>で別に作ったページが表示されるようにしているのですが、 リロードするたびに<iframe>内のページがランダムに入れ替わり、 いろんなページが見られるようにしたいと思っています。 現在このようなソースでtest1.htmlを表示させているのですが、 ここにtest2.html、test3.html、test4.htmlが表示されるように するにはどうしたらいいでしょうか? <iframe src="../test1.html" name="sample" width="500" height="500" frameborder="0" scrolling=no> この部分はインラインフレームを使用しています。 </iframe>

    • ベストアンサー
    • HTML
  • iframeが正しく表示されません

    #box1{ width: 595px; float: left; height: 570px; margin-top: 70px; margin-left: 10px; border: 1px solid #000000; } <div id="box1"> <iframe src="http://astore.amazon.co.jp/uraren-22" width="100%" height="100%" frameborder="0"></iframe> </div> とゆう表記でHPを作成したのですが、IEではちゃんと表示されるのですがfirefoxやsafariですと、box1の中に表示されず下にずれ、スクロールバーが表示されなかったりもします。 解決方法をお願いします。

    • ベストアンサー
    • HTML

専門家に質問してみよう