NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Webmaster Tutorials
Reload this Page Howto: Change Variables Between Windows With JavaScript

Webmaster Tutorials Instructional webmaster-related how-to's and tutorials.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 08-09-2003, 06:28 AM THREAD STARTER               #1 (permalink)
NamePros Member
 
Mp)Tarh's Avatar
Join Date: Aug 2003
Location: Ontario, Canada
Posts: 98
Mp)Tarh is an unknown quantity at this point
 



Howto: Change Variables Between Windows With JavaScript


Have you always wanted to communicate between windows like the parent and child and change variables or other unchangable material? Well today is your lucky day!

Just recently, while designing my latest site, I came up with a way to comunicate whatever you want between windows without using build in javascript functions. Want to know how to do it?

USE THE STATUS BAR

Ever thought of that before?

There are somne security issues and it is not foolproof, but hey - what do you have to lose in these situations?

Here is an example.

Parent window (default browser window) opens up a Child window names (New_Window).

The parent window has a variable called "hello" with the string of "not_set" - The child window wants to change the string in this variable to "set".

This is the code in the child window:

----------Child Window----------
<HTML>
<HEAD>
<TITLE> </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- hide me
????: NamePros.com http://www.namepros.com/webmaster-tutorials/15106-howto-change-variables-between-windows-javascript.html
function myfunc()
{
top.window.opener.status = "action change var hello value set";
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<button onClick="myfunc()">Click me!</button>
</BODY>
</HTML>
------------------------------
Now you might be saying "What was the good in that?", this is why.

Consider this code in the parent window:
----------Default Window----------
<HTML>
<HEAD>
<TITLE>My Page</TITLE>
</HEAD>
<BODY>
<A HREF="javascript:void(1)" onClick="window.open('secondpage.htm','new_window' ,'resizable')">Open second window</a>


<!-- Here is the part you want to pay attention to: -->
<SCRIPT LANGUAGE="JavaScript">
<!-- hide me
var timeout_1;
var hello;
hello = "not_set";

function repeating_func()
{
// You could make the next part a function if you
// wanted to..

if (top.window.status == "action change var hello value set")
{
hello = "set";
top.window.status = "Done";
}

timeout_1 = setTimeout("repeating_func()",100);
}

repeating_func();
//-->
</SCRIPT>

Now obviously it isn't the best code in the world for security and for speed, but this small start should probably get us further into finding a foolproof way to do these things...

Feel free to post your modifications of the code if you have done so.
__________________
Yeah... I knew that. What?
Mp)Tarh is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 01:33 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger