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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inter-window communication

Status
Not open for further replies.

Jonathan

Programmer
Mar 19, 1999
116
GB
I am writing some pages using Javascript as my main scripting language. The pages are for an intranet, so I know that all users will have IE5.5. What I'm trying to do is find out a way of calling a function defined in one page in another.

My script on page A opens page B in a separate window. Then I want to be able to pass data first from A to B, preferably calling a function in B, and possibly then pass some data back. How do I do it!

Thanks in advance... Jonathan
jon_george1@hotmail.com

Working against: Visual Basic, Access, Visual Interdev, VBScript, JavaScript, Active Server Pages, SQL Server, Oracle, XML
 
I am no javascript expert but I beleive you can create variables then write those variables such as document.write(myVariable) to the window.

You can call the functions all you like but the data you pass must be a variable. Any JavaScript tutorial should help with this.

Hope this can give you a start
 
I'm not entirely sure what you mean by this. I understood that document.write is for writing new content to a page, rather than setting the value of a variable in that page. And I still can't work out how to call a function in the new page from the original page when they are both open in separate windows.

Any other ideas?

Cheers Jonathan
jon_george1@hotmail.com

Working against: Visual Basic, Access, Visual Interdev, VBScript, JavaScript, Active Server Pages, SQL Server, Oracle, XML
 
Jonathan,
Here is one way to do it (not sure if it's exactly what you were looking for, but here goes). I put an include statement in window1.asp that includes window2.asp. That way, window1.asp has access to any function defined in window2.asp. To test it out, I called a function defined in window2.asp from window1.asp, passing it a parameter. The function in window2.asp then returned a value to window1.asp and I just did a 'document.write' so I could see the value it returned. I'm sure there's another way to do this, so keep me posted if you're looking for another way.

Julie

Here is window1.asp:

<HTML>
<HEAD>
</HEAD>
<BODY>
<!--#include file=&quot;window2.asp&quot;-->
<SCRIPT LANGUAGE=javascript>
<!--
var anotherWindow = window.open('window2.asp', 'myWin')
var a = 1;
var result;
result = window2Function(a);
document.write (&quot;And the answer is &quot; + result);
//-->
</SCRIPT>


</BODY>
</HTML>


Here is window2.asp:

<HTML>
<HEAD>
</HEAD>
<BODY>

<SCRIPT LANGUAGE=javascript>
<!--
function window2Function(myVar) {
return myVar * 2;
}
//-->
</SCRIPT>

</BODY>
</HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top