4

I'm trying to target an iframe's source from a javascript form. So if someone typed in http://www.reddit.com the iframe's source would change to reddit.com I've tried a few things but you can't put a script tag within src, so is there any way to do this with javascript, or would i need to make a php echo function?

<iframe  src="http://www.stachoverflow.com/"></iframe>
1
  • typed where? in address line of the browser? Commented Dec 23, 2012 at 0:27

2 Answers 2

3

Do you mean something like this?

<input type="url" placeholder="http://example.com/" /><button id="urlclick">Go</button>
<iframe id="frm"></iframe>

<script type="text/javascript">
  document.getElementById('urlclick').onclick = function() {
    document.getElementById('frm').src = this.previousSibling.value;
    return false;
  }
</script>
Sign up to request clarification or add additional context in comments.

Comments

0

By using jquery we can do like this..

<input type="text" id="address">
<button onclick="get_url()"></button>
<iframe id="frm"></iframe>

<script>
function get_url()
{
var adr=$('#address').val();
$('#frm').attr('src', url);
}
</script>

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.