How do you load a URL from a text box into iframe in a HTML file via javascript?
+7
A:
var oIFrame = document.getElementById("id_of_iframe");
oIFrame.src = document.getElementById("id_of_textbox").value;
marduk
2009-05-25 17:58:12
I would modify that to add error checking at each step: `if (oIFrame != null)...`
Cerebrus
2009-05-25 18:05:58
A:
Or with document.frames if its the only iframe you are using:
var myIframe = window.document.frames[0]; // lets grab the iframe object
if (myIframe != null){
myIframe.src = document.getElementById("id_of_textbox").value; // set the value as source.
}
vsync
2009-05-25 21:15:48
A:
Just to add I guess, via jQuery
$('iframe#guid').src( $('#textbox_id').val() );
with error checking:
var iframe = $('#guid');
if(iframe.length > 0){
iframe.attr('src', $('#textbox_id').val());
}
Dmitri Farkov
2009-05-25 21:20:35