Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do you write text to a frame inside a new window?

Status
Not open for further replies.

estesflyer

Programmer
Dec 19, 2000
284
US
could someone tel me how to write text to a frame inside a new window, from the base window.
like, to write code to a new window, you would put
newwin.document.write("text text text");

how would you write code to the new window's frames?
 
well, here is part of my script (but its all you need to see) maybe it will help.
Code:
<script language=&quot;javascript&quot;>
<!--
function searchnet()
{
var searchurl=document.searchform.searchlist.value + document.searchform.searchquery.value;
var newwin=window.open(&quot;about:blank&quot;,&quot;newwin&quot;,&quot;status&quot;);
newwin.document.write(&quot;<html>&quot;);
newwin.document.write(&quot;<head>&quot;);
newwin.document.write(&quot;<title>Search Window</title>&quot;);
newwin.document.write(&quot;</head>&quot;);
newwin.document.write(&quot;<frameset rows=10%,90%>&quot;);
newwin.document.write('<frame src=&quot;about:blank&quot; name=&quot;topwin&quot;>');
newwin.document.write(&quot;<frame name=topwin src=&quot; + searchurl + &quot;>&quot;);
newwin.document.write(&quot;</frameset>&quot;);
newwin.topwin.document.write('Click <a href=&quot;#&quot; onClick=&quot;self.close&quot;>here</a> to close this window.')
}
//-->
</script>
 
Code:
hey, say that you write code for a new window right?

var newwindow=window.open(&quot;about:blank&quot;,&quot;newwin&quot;,&quot;navbar&quot;);

ok, now we want to write text to the new win right?
newwindow.document.write(&quot;Hello World!&quot;);

now lets say that we have frames in the new window

newwin.document.write(&quot;<html>&quot;);
newwin.document.write(&quot;<head>&quot;);
newwin.document.write(&quot;<title>Search Window</title>&quot;);
newwin.document.write(&quot;</head>&quot;);
newwin.document.write(&quot;<frameset rows=10%,90%>&quot;);
newwin.document.write('<frame src=&quot;about:blank&quot; name=&quot;topwin&quot;>');
newwin.document.write(&quot;<frame name=topwin src=&quot; + searchurl + &quot;>&quot;);
newwin.document.write(&quot;</frameset>&quot;);

now we know that the new window has frames, and one of the frames (the bottom frame) has a URL opening into it, but the top, well, has nothing, so we want to write text into it. do you know how to do that?
 
Just address it as usual, like:
[colorred]
newwin.topwin.document.write(&quot;Hello World!&quot;);
[/color]
This should work, but depending on where you are calling from, you might have to address it using parent. The above code works when using code from original window.

If calling from the pop-up, i.e. from the bottom frame just use:

parent.topwin.document.write();


hope this helps, Ben. &quot;Alright whatever man, I'll hook up the hair, but I aint touchin the ring...Cause I'm still a pla--yer&quot;
 
ok, so now, it works, great!

but I would also like to know, how to change it so it will work when the user presses enter, and doesnt HAVE to click on the button. I mean, it works fine as it is, but if you press enter, it just reloads the page....

<!--

//Script Written by Rusty Estes (Estes_Flyer)
//This script is not copyright, but I would appreciate it if you would ask me before you take it for your own use.

Code:
<script language=&quot;javascript&quot;>
<!--
function searchnet()
{
var searchurl=document.searchform.searchlist.value + document.searchform.searchquery.value;
var newwin=window.open(&quot;about:blank&quot;,&quot;newwin&quot;,&quot;status,top=5,left=5,width=700,height=500&quot;);
newwin.document.write(&quot;<html>&quot;);
newwin.document.write(&quot;<head>&quot;);
newwin.document.write(&quot;<title>Search Window</title>&quot;);
newwin.document.write(&quot;</head>&quot;);
newwin.document.write(&quot;<frameset resizable=no rows=10%,90%>&quot;);
newwin.document.write('<frame src=&quot;about:blank&quot; name=&quot;topwin&quot; scrolling=&quot;no&quot;>');
newwin.document.write(&quot;<frame name=bottomwin src=&quot; + searchurl + &quot;>&quot;);
newwin.document.write(&quot;</frameset>&quot;);
newwin.topwin.document.write('Click <a href=&quot;#&quot; onClick=&quot;top.self.close;&quot;>here</a> to close this window');
}
//-->
</script>
</head>
<body>
<form method=&quot;post&quot; name=&quot;searchform&quot;>
<input value=&quot;My Search&quot; type=&quot;textbox&quot; size=&quot;17&quot; name=&quot;searchquery&quot;>
<table border=&quot;0&quot; width=&quot;0&quot; height=&quot;8&quot;>
<tr><td></td></tr></table>
<select name=&quot;searchlist&quot;>
<option value=&quot;[URL unfurl="true"]http://www.altavista.com/cgi-bin/query?q=&quot;>Altavista.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://www.lycos.com/srch/?lpv=1&amp;loc=searchhp&amp;query=&quot;>Lycos.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://hotbot.lycos.com/?MT=&quot;>Hotbot.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://www.google.com/search?q=&quot;>Google.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://www.nbci.com/search/directory/results/1,61,-0,00.html?tag=fd.srch.bar&amp;keyword=&quot;>NBCI.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://www.alltheweb.com/cgi-bin/search?type=all&amp;query=&quot;>AllTheWeb.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://www.go.com/Split?pat=go&amp;col=WW&amp;qt=&quot;>Go.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://www.goto.com/d/search/;$sessionid$3O2HCYAAAAEQ3QFIEOSQPUQ?type=home&amp;Keywords=&quot;>GoTo.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://www.search.com/search?channel=1&amp;tag=ex.cn.1.srch.web&amp;q=&quot;>Search.com(Cnet)</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://search.yahoo.com/bin/search?p=&quot;>Yahoo.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://search.dogpile.com/texis/search?q=&quot;>DogPile.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://search.excite.com/search.gw?search=&quot;>Excite.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://search.msn.com/results.asp?RS=CHECKED&amp;FORM=MSNH&amp;v=1&amp;q=&quot;>Msn.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://www.galaxy.com/bin/search?q=&quot;>Galaxy.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://www.geosites.com/cgi-bin/search.cgi?query=&quot;>Geosites</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://www.looksmart.com/r_search?look=&amp;pin=010107x30af599d65a4b8c2581&amp;key=&quot;>LookSmart.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://www.infind.com/infind/infind.exe?query=&quot;>Inference.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://search.dogpile.com/texis/search?q=&quot;>InfoSpace.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://www.matilda.com/cgi-bin/fetch.cgi?terms=&quot;>Matilda.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://www.mamma.com/Mamma?p1=1&amp;timeout=4&amp;query=&quot;>Mamma.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://search.metacrawler.com/crawler?general=&quot;>Metacrawler.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://www.accufind.com/bin/Search?keywords=&quot;>Accufind.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://www.northernlight.com/nlquery.fcg?cb=0&amp;qr=&quot;>NorthernLight.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://www.directhit.com/search.asp?qry=&quot;>DirectHit.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://www.ask.com/main/askjeeves.asp?ask=&quot;>Ask.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://partners.mamma.com/Findit?lang=1&amp;timeout=4&amp;query=&quot;>FindIt.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://thunderstone.master.com/texis/master/search/mysite.html?q=&quot;>Thunderstone.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://search.megaspider.com/XP.html?&quot;>MegaSpider.com</option>[/URL]
<option value=&quot;[URL unfurl="true"]http://search.iwon.com/commerce/multisearch.jsp?searchfor=&quot;>Iwon.com</option>[/URL]
</select><table border=&quot;0&quot; width=&quot;0&quot; height=&quot;8&quot;>
<tr><td></td></tr></table>
<input type=&quot;button&quot; onClick=&quot;searchnet()&quot; value=&quot;Search&quot;>
</form>

all suggestions/comments WILL be apreciated!

- Rusty
 
You need to make sure the correct thing has focus at the time the enter key is pressed. Do this by setting the tabindex property of Form elements:

<input type=&quot;button&quot; tabindex=&quot;1&quot;...>
I presume you want to enable the enter press after a text field is filled , or some such thing?

You could make sure your button is next in order, or I suppose apply focus to it at some point, like when focus leaves a text field or whatever.

I'm not sure this is what you mean though.
-I do not think it is possible to capture the enter key press, character keys only.

Which page is reloading itself?[/blue]
&quot;Alright whatever man, I'll hook up the hair, but I aint touchin the ring...Cause I'm still a pla--yer&quot;
 
You need to make sure the correct thing has focus at the time the enter key is pressed. Do this by setting the tabindex property of Form elements:

<input type=&quot;button&quot; tabindex=&quot;1&quot;...>
I presume you want to enable the enter press after a text field is filled , or some such thing?

You could make sure your button is next in order, or I suppose apply focus to it at some point, like when focus leaves a text field or whatever.

I'm not sure this is what you mean though.
-I do not think it is possible to capture the enter key press, character keys only.

Which page is reloading itself?
&quot;Alright whatever man, I'll hook up the hair, but I aint touchin the ring...Cause I'm still a pla--yer&quot;
 
you can, however, capture onkeydown and onkeyup events of the enter key (i thinks its keycode is 13). These events happen before onkeypress. jared@aauser.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top