私は、ページが読み込まれたときに特定のテキストを表示したい、ボタンがクリックされたときに同じテキスト(伝記)を表示するコンテンツ領域を持っています。別のボタン(AFT)をクリックすると、コンテンツ領域のテキストをiFrame経由でURLのコンテンツに置き換えます。javascriptを使用して、ボタンをクリックしたときにコンテンツ領域をiframeに置き換える方法は?
ページが読み込まれたときに適切なテキストを表示することができましたが、「AFT」ボタンをクリックすると、iframeを表示する代わりにテキストが「[object HTMLIFrameElement]」に置き換えられます。誰かが間違っていることを知っていますか?
HTMLコード:
<div id="content" >
<script src="myJS.js"></script>
<script> displayBiography(); </script>
<iframe src="cwExample.pdf" name="iframe" id="iframe1"></iframe>
</div>
<div id="leftBar">
<br><br>
<button class="button" type="button" onclick="displayBiography();">
Biography </button>
<h3> Samples of Work </h3>
<button class="button" type="button" onclick="toShow();"
target="#iframe1"> AFT </button>
JSコード:
var content = document.getElementById("content");
var biography = "<p> Text here </p>"
;
function displayBiography() {
"use strict";
content.innerHTML = biography;
}
window.onload = function() {
var iframe = document.getElementById('iframe1');
iframe.style.display = 'none';
}
function toShow() {
var iframe1 = document.getElementById('iframe1');
content.innerHTML = iframe1
biography.style.display = 'none';
iframe1.style.display = 'block';
}
jquery APIと '.replaceWith()'関数を使用できます – shahabvshahabi
これはこの関数チュートリアルのリンクです: http://api.jquery.com/replacewith/ – shahabvshahabi