load iframe with a user-specified url

B

bhosle

hi ppl..
i'm new to jsp and iframes.. and here is what i want to do - take
input from the user in a form, and load an iframe with that url..
any suggestions?

thx..
AB
 
R

RobG

(e-mail address removed) said on 17/03/2006 4:20 PM AEST:
hi ppl..
i'm new to jsp and iframes.. and here is what i want to do - take


I guess you're asking how to load it directly into the iFrame without
going back to the server using JavaScript.

input from the user in a form, and load an iframe with that url..
any suggestions?

Set the location attribute of the iFrame to the value of the input text.
You may want to do some validation on the input string to make sure it
looks a bit like a URL first.

If JavaScript is disabled, the form will be submitted so have your
server return the page.

<script type="text/javascript">
function loadFrame(el)
{
var f;
var fName = el.form.target;
if (fName && (f = window.frames) && (f = f[fName])){
f.location = el.value;
return false;
}
return true;
}
</script>

<form action="" target="foo"
onsubmit="return loadFrame(this.URL);"><p>
<input type="text" size="100" name="URL"><input
type="submit" value="Load URL">
</p></form>

<iframe id="foo" name="foo" width="50%"></iframe>



Of course if you use links, you don't need script at all:

<a href="http://www.apple.com/" target="foo">Load Apple in foo</a>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,017
Latest member
GreenAcreCBDGummiesReview

Latest Threads

Top