/    Sign up×
Community /Pin to ProfileBookmark

gotoURL in iframe

hi there,

im a complete newbie to javascript so apologies is this is a relatively simple thing but i am currently developing a sort of ‘browser-in-browser’ type thing using a text input form and JS, heres the code:

[CODE]<html>

<head>
<meta name=”GENERATOR” content=”Microsoft FrontPage 5.0″>
<meta name=”ProgId” content=”FrontPage.Editor.Document”>
<meta http-equiv=”Content-Type” content=”text/html; charset=windows-1252″>
<title>Divisions: Product Design</title>

<SCRIPT>
function gotoURL(){
var newURL = document.GotoForm.theURL.value
document.location.href=newURL
}
</SCRIPT>

</head>

<body bgcolor=”000000″ text=”FFFFFF”>
<center>
<br>
<iframe src=”http://www.myspace.com/” name=”browser” width=”95%” height=”80%” frameborder=1>
if you cant see this you suck ;-)</iframe>
<br><br>
<FORM ACTION=”JavaScript:gotoURL()” METHOD=”GET” NAME=”GotoForm”>
URL:
<INPUT TYPE=”text” NAME=”theURL” value=”http://” REQUIRED SIZE=”50″ MAXLENGTH=”100″>
<INPUT TYPE=”submit” VALUE=”GO”>
<br><br>
teachers pwned by -snap-
</center>
</body>

</html>[/CODE]

it currently works fine for opening the page at the top of the current one but i would like the pages to load in the iframe every time the form is submitted…

thanks in advance

adam

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@FromU2MEDec 07.2005 — Use this:

<FORM ACTION="javascript:gotoURL()" METHOD="GET" NAME="GotoForm" [B]target="browser"[/B]>

Then the form will be sent to the iframe instead of the parent window (the window that contains the form).

Good luck!
Copy linkTweet thisAlerts:
@Krogh_DKDec 07.2005 — <SCRIPT>

function gotoURL(){

var newURL = document.GotoForm.theURL.value

window.open(newURL, 'browser')

}

</SCRIPT>
Copy linkTweet thisAlerts:
@FromU2MEDec 07.2005 — In your case (I noticed) you should use this instead:

[CODE]<script language="JavaScript">
<!--

function gotoURL() {

browser.document.location.href = document.gotoForm.getURL.value;

}

//-->
</script>[/CODE]


And change your HTML form code to:

[code=html]<form method="post" action="" name="gotoForm" onsubmit="gotoURL()">[/code]
Copy linkTweet thisAlerts:
@KorDec 07.2005 — Try this simple

[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
</head>
<body>
<iframe id="myifr" src="http://www.myspace.com/" width="95%" height="80%" frameborder="1"></iframe>
<input type="text" value="http://" id="url">
<input type="button" value="GO" onclick="document.getElementById('myifr').contentWindow.location.href=document.getElementById('url').value">
</body>
</html>
[/code]


if you cant see this you suck ;-)
[/quote]

Don't write that. Try to be polite when building a site.
Copy linkTweet thisAlerts:
@snap6sic6authorDec 07.2005 — excellent thanks very much people!

Don't write that. Try to be polite when building a site.[/QUOTE]

heh dont worry this is only going to be used by myself and friends of mine, i've designed enough sites in the past to know not to insult people! ?

anyways thanks again!
×

Success!

Help @snap6sic6 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...