0

How do you load a URL from a text box into iframe in a HTML file via javascript?

3 Answers 3

7
var oIFrame = document.getElementById("id_of_iframe");
oIFrame.src = document.getElementById("id_of_textbox").value;
Sign up to request clarification or add additional context in comments.

1 Comment

I would modify that to add error checking at each step: if (oIFrame != null)...
0

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.
}

Comments

0

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());
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.