2012-05-06 17 views
3

以下のhrefリンクで2つのことを達成しようとしています。まず、ポップアップウィンドウを開きたいと思います。完了しました。次に、そのポップアップウィンドウにiframeを表示したいと思います。これは容易に達成されましたまで私はiframe srcのパラメータとしてhrefリンクのテキストを渡す必要があることに気づきました。例えばのでポップアップウィンドウの動的iframe

、そのsrc="http://localhost:8080/test/document.html?OnSale"

ない限り、私のポップアップウィンドウ内のiframe文句を言わないの負荷私のhtmlページの本文にdocument.writeを作成しようとして動的なiframeのイムをプリントアウトしませんなぜ私は把握することはできませんhrefのリンクの私のfoo()関数を使用して...

<div id="blanket" style="display:none;"></div> 
    <div id="popUpDiv" style="display:none;"> 
     <a href="#" onclick="popup('popUpDiv')"> 
      <img align="right" src="http://localhost:8080/test/img/close_img.png"> 
     </a> 
<script type="text/javascript"> 
    function foo(obj) 
    { 
     test1 = "http://localhost:8080/test/document.html?"+obj.text; 
     document.write('<iframe height="450" allowTransparency="true" frameborder="0" scrolling="yes" style="width:100%;" src="'+test1+'" type= "text/javascript"></iframe>'); 
    } 
</div> 

<a href="#" onclick="popup('popUpDiv');foo(this);">OnSale</a> 

編集:ここでは は私の完全なHTMLページです。すべてtomcat7 w/win7とfirefoxでローカルに実行されています。

<html> 
<head> 
    <script type="text/javascript" src="http://localhost:8080/test/css-popup/css-pop.js"></script> 
    <link href="http://localhost:8080/test/css-popup/styles.css" rel="stylesheet" type="text/css" /> 
</head> 
<body> 
<div id="blanket" style="display:none;"></div> 
<div id="popUpDiv" style="display:none;"> 
    <a href="#" onclick="popup('popUpDiv')"> 
     <img align="right" src="http://localhost:8080/test/css-popup/x.png"> 
    </a> 
    <script type="text/javascript"> 
     function foo(obj){ 
      test1 = "http://localhost:8080/test/document.html?"+obj.innerHTML; 
      document.write('<iframe height="450" allowTransparency="true" frameborder="0" scrolling="yes" style="width:100%;" src="'+test1+'" type= "text/javascript"></iframe>'); 

     } 
    </script> 
</div> 

<a href="#" onclick="popup('popUpDiv');foo(this);">OnSale</a> 
</body> 
</html> 

答えて

3

text私はあなたがしたい理解としてすべてのブラウザのための標準ではありません、代わりにそのinnerHTMLを試してみてください、あなたはあなたの全体のコードを共有していた後に更新

function foo(obj){ 
    test1 = "http://localhost:8080/test/document.html?"+obj.innerHTML; 
    document.write('<iframe height="450" allowTransparency="true" frameborder="0" scrolling="yes" style="width:100%;" src="'+test1+'" type= "text/javascript"></iframe>'); 
} 

ポップアップウィンドウを開き、そこに動的に作成されたiframeを表示します。しかし、document.writeはあなたの現在のウィンドウで動作します。だから最初はあなたのポップアップウィンドウを操作する必要があります。その内容を変更します。

は、私は、ヘルプocanalに感謝

<html> 
<head> 
<script type="text/javascript" src="http://localhost:8080/test/css-popup/css-pop.js"></script> 
<link href="http://localhost:8080/test/css-popup/styles.css" rel="stylesheet" type="text/css" /> 
</head> 
<body> 


<div id="blanket" style="display:none;"></div> 
    <div id="popUpDiv" style="display:none;"> 
     <a href="#" onclick="popup('popUpDiv')"> 
      <img align="right" src="http://localhost:8080/test/css-popup/x.png"> 
     </a> 
<script type="text/javascript"> 
    var popUpWindow; 
    function popup(n) { 
     popUpWindow = window.open(n); 
    } 
       function foo(obj){ 
       test1 = "http://localhost:8080/test/document.html?"+obj.innerHTML; 
       popUpWindow.document.write('<iframe height="450" allowTransparency="true" frameborder="0" scrolling="yes" style="width:100%;" src="'+test1+'" type= "text/javascript"></iframe>'); 

       } 
     </script> 
</div> 

     <a href="#" onclick="popup('popUpDiv');foo(this);">OnSale</a> 

</body> 
</html>​ 

そしてhere is working live DEMO

+0

、これを試してみてください。 innerHTMLはどちらもしませんでしたが、標準ではないテキストについて学ぶのは良いです。 – Chris

+0

@Chris、私の更新された答えをもう一度見てください。 – ocanal

+0

ocanal、ありがとう!これは完全にiframeを開きますが、Firefoxでは新しいタブとしてポップアップウィンドウではなく開きます。 window.open(n)が新しいタブの代わりにポップアップする方法はありますか? – Chris

関連する問題