I'm an html noob and I just wanted to know if it's possible to make a text box in which you could type a website and when you click submit it will load the website in the iframe of your choice.
A:
<html>
<head>
<script language="JavaScript">
function SendMe()
{
document.all.myframe.src = document.forms[0].txtval.value;
}
</script/>
</head>
<body>
<form name="myform">
<input type="text" name="txtval">
<input type="button" value="Go" onclick="javascript:SendMe()">
<br>
<iframe src="http://www.google.com" width="400" height="200" name="myframe"></iframe>
</form>
</body>
</html>
Bhaskar
2009-08-11 15:21:25
I tried but when I click go the website isn't loaded in the iframe, instead the url in the browser changes but I don't see any changes, just google inside the iframe.When I type a url into the text box and hit go the browsers url changes to this http://mydomain.com/index.html?txtval=www.yahoo.com
2009-08-11 15:59:34
document.all? Did you stop developing websites around the time IE4 was still popular? -1.
Lior Cohen
2009-08-11 17:08:59
make the following changes--> <form name="myform" action="post">
Bhaskar
2009-08-12 07:11:19
A:
<html>
<head>
<title> Answer </title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(function()
{
$('.frmSubmit').click(function(e)
{
$('#dynFrame').attr('src', $('.frmUrlVal').attr('value'));
e.preventDefault();
});
});
</script>
</head>
<body>
<form>
<input type="text" class="frmUrlVal">
<input type="submit" class="frmSubmit" value="Go">
</form>
<iframe src="http://www.google.com" width="100%" height="400" id="dynFrame"></iframe>
</body>
</html>
Lior Cohen
2009-08-11 17:05:43
A:
ty ty the second code did exactly what I wanted :)
Just one more question... sorry
Is there a way to force the content of the iframe to stay inside it at all times?
Using this code please :)
Answer $(function() { $('.frmSubmit').click(function(e) { $('#dynFrame').attr('src', $('.frmUrlVal').attr('value')); e.preventDefault(); }); });
P.s - sorry didn't see it said answer question..
You can't force the content to stay inside the iframe at all times since you cannot modify the content loaded into the IFrame (cross domain policy - google about it).
Lior Cohen
2009-08-11 21:03:30