2016-11-23 14 views
-1

ユーザーが別のinputを選択してgetPriceボタンを再度クリックすると、iframeを置き換えたいと思います。コードを書いていくつか試しましたが、何も問題はありませんでした。たびに私はdocument.body.appendchild()を使用することはできません。私のコードは以下の通りです。ここで提案してください。はOnlclickに基づいてiframeを置き換えたい

function getPrice()[ 
var ifrm = document.createElement('iframe'); 
    ifrm.id = "frameID"; 
ifrm.setAttribute('src', 'http://40.85.176.227/invoke/Tier1ICLStd_New.Price/getPrice?CloudName=Azure East 
ifrm.setAttribute('align', 'right'); 
//ifrm.setAttribute('marginheight', '50'); 
ifrm.style.margin= "auto"; 
ifrm.scrolling="no"; 
ifrm.style.border= "0"; 
ifrm.style.margin= "0"; 
//document.body.insertBefore(ifrm, document.body.firstChild); 
//alert(); 
if(document.getElementById("frameID")==null) 
{ 
document.body.appendChild(ifrm); 
} 
else 
{ 
alert("Else"); // I am getting control till here but what code to replace the existing iframe. 
//var item = document.getElementById("frameID").childNodes[0]; 
item.replaceChild(ifrm,item.childNodes[0]); 
alert("test"); 
    document.body.appendChild(ifrm); 

//ifrm.parentNode.replaceChild(ifrm, ifrm); 
} 
} 
+0

あなたは構文エラーがあります: '関数getPriceを()[' '関数getPrice(){' –

+0

'ifrm.setAttribute( 'SRC'、「HTTPでなければなりません://40.85.176.227/invoke/Tier1ICLStd_New.Price/getPrice?CloudName = Azure East '); 'あなたのコードはこのようなものでしょうか? –

+0

完全なIframeまたはその内容を置き換えたいですか? –

答えて

0

あなたはiframeのコンテンツを更新する場合は、ちょうどこのようなものを使用する必要があります:

function updateIframeSrc(newSrc) { 
    document.getElementById("frameID").src = newSrc; 
} 

EDIT:コメントに答えるためにHTMLの宣言でexempleを追加します。 jQueryのなし

<div class="frameClass"> 
    <iframe id="frameID" width="100%" height="1080" frameborder="0" scrolling="auto" marginheight="0" marginwidth="0" 
     src="http://svn.min.not/metasite/trunk/docs/README.md"> 
    </iframe> 
</div> 
+0

document.getElementById( "iframeID")。src = 'http:// xyz';働いていませんでした。何も起こらなかった – samash

+0

humm ...あなたは "frameID"、 "iframeID"ではない...私は自分の答えを編集する^^。 これは、私はそれがいくつかのWebページと同じように使っています。 –

+0

WOW !!!!!ありがとうございます。あなたはそれをキャッチしました...私はこれも以前に試しました。しかし、私はこれをキャッチしていなかったと思っています....たくさんのことをやってくれました。私のためにも働いています...しかし、どういうわけか、これは左か右どちらかの中心に来ていません... – samash

0

var i = 0; 

var ifrm = document.createElement('iframe'); 
ifrm.id = "frameID"; 
ifrm.setAttribute('align', 'right'); 
ifrm.style.display="none"; 

document.body.appendChild(ifrm); 

function getPrice(){ 
    ifrm.setAttribute('src', 'http://40.85.176.227/invoke/Tier1ICLStd_New.Price/getPrice?CloudName=Azure East&token=' + i); 
    ifrm.style.display = "inline"; 
    i ++; 
} 
+0

クラウドプロバイダーによってサーバーが維持されているため、JQueryを使用できません。代わりを提案してください。 – samash

+0

私の答えを更新しました – Joe

関連する問題