View previous topic :: View next topic |
Author |
Message |
phil karras
Senior Member

Joined: 15 Jul 2002
Posts: 1697
Location: MD
|
Posted: Wed Aug 28, 2002 9:07 am Post subject: HINT: On Passing Data |
 |
|
To pass data between frames:
Assume in our frame set we have: Left, Center, Right frames.
Then in Center or Right we use: parent.Left.Var01 = 15; to change the value of Var01 in the Left frame.
To Pass data to/from a Pop-up window:
In the pop-up we use: window.opener.Var01 = 15; to change the value of Var01 in the original window.
In the original window we use: var NewWin = window.open(URL, "Child"); and then NewWinVar02 = 15.67; to change a value in the pop-up window.
WARNING The pop-up window MUST be open and ready for data before you issue the NewWin.Var02 = 15.67; line or no data will be passed!
Now, one last topic, to actually use or do something when a piece of data changes we could use a function like this in the <head> section:
Code: |
var Var01 = 0;
var LastVal = Var01;
function CheckUm() {
if(Var01 != LastVal) {
// Here we do whatever!
alert("Var01 value has changed from "+LastVal+" to "+Var01);
LastVal = Var01;
}
setTimeout("CheckUm();" 500); // check again in 1/2 sec.
}
.
.
.
<body onLoad="CheckUm();">
.
.
.
|
Now in any frame or window where we want to be able to do something when a given value changes we can.
Passing data between secondary related windows:
The only way I know to do this is via a cookie.
Frames and window.opener/child are directly related, a secondary relationship is a window opened from the same site but not by the initial window. All windows opened by the same site & location can access the same cookie. See my other article on Cookies:
http://jsworkshop.com/bb/viewtopic.php?t=15
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508
|
|
Back to top |
|
 |
phil karras
Senior Member

Joined: 15 Jul 2002
Posts: 1697
Location: MD
|
|
Back to top |
|
 |
anamika
New member

Joined: 27 Mar 2003
Posts: 2
|
Posted: Fri Mar 28, 2003 5:22 am Post subject: |
 |
|
thx,
was'nt exactly what I wanted, but got the idea. Was looking for a solution like window.showModalDialog(), but it does not works in netscape.
Can you suggest anything else. |
|
Back to top |
|
 |
phil karras
Senior Member

Joined: 15 Jul 2002
Posts: 1697
Location: MD
|
|
Back to top |
|
 |
sohnee
Senior Member

Joined: 17 Jul 2002
Posts: 922
Location: UK
|
Posted: Thu Apr 17, 2003 9:04 am Post subject: Passing data to an iframe |
 |
|
You can also pass data to and from an <iframe>
Firstly, set up your iframes with a name:
Code: |
<iframe src="about:blank" name="iframe1"></iframe>
<iframe src="about:blank" name="iframe2"></iframe>
|
In the main page you simply use the iframe name to call the function, variable or object you want. From an iframe, you can call functions variables and objects in the main page OR another iframe.
This is how you could do all of these things in one example...
save this as 'iframeexample.html'
Code: |
<html>
<head>
<title>iframe example 1.0</title>
<script LANGUAGE="JavaScript" type="text/javascript">
var wot;
function anothertest(){
alert("This alert is from the parent.");
}
</script>
</head>
<body>
<p>Save this bit as 'iframeexample.html'</p>
<p><a href="#" onClick="iframe1.location.href='http://www.odford.co.uk';">Change the location of IFRAME 1</a></p>
<p><a href="#" onClick="iframe2.test();">Launch a function in IFRAME 2</a></p>
<p>
<iframe src="about:blank" name="iframe1" width="600" height="400"></iframe>
</p>
<p>
<iframe src="pagetwo.html" name="iframe2" width="400" height="200"></iframe>
</p>
</body>
</html> |
save this as 'pagetwo.html'
Code: |
<html>
<head>
<title>iframe example 1.0 - Page Two</title>
</head>
<body>
<p>Save this bit as 'pagetwo.html' in the same folder</p>
<p id="one"><a href="#" onClick="parent.iframe1.location.href='http://www.northernline.net';">Change the location of IFRAME 1 from IFRAME 2 via the 'parent' window.</a></p>
<p id="two"><a href="#" onClick="parent.anothertest();">Launch a function in 'Parent'</a></p>
<script LANGUAGE="JavaScript" type="text/javascript">
function test() {
alert('THIS ALERT HAS COME FROM IFRAME 2 - PAGE TWO');
}
</script>
</body>
</html> |
|
|
Back to top |
|
 |
phil karras
Senior Member

Joined: 15 Jul 2002
Posts: 1697
Location: MD
|
Posted: Tue May 13, 2003 8:00 am Post subject: Basic function calling conventions: |
 |
|
Basic function calling convention, from the "top" frame:
If you put the function in the <head> section, then the form of an outside refernece is: parent.top.updateMe();. The correct form when the function is placed in an iframe (called: headerDiv) is: parent.top.frames.headerDiv.updateMe();
Reference: Unable to reference a function in another dhtml layer NS 7.0
http://jsworkshop.com/bb/viewtopic.php?t=855
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508 |
|
Back to top |
|
 |
phil karras
Senior Member

Joined: 15 Jul 2002
Posts: 1697
Location: MD
|
Posted: Wed Aug 06, 2003 11:01 am Post subject: Passing Data from one page to another using <form> &am |
 |
|
There's is one more passing data topic that should be covered. It is passing data from a form on one page to another page. In this case the form posts the data, it gets placed in the URL and the new page looks at its URL and picks up the data. Once you have the data you can do whatever you want to it, place it into fields of a new form or whatever.
Here is the form in help266.htm:
Code: |
<form name='test' post='help266.htm'>
Enter your name: <input type='text' name='Name'>
<input type='submit' name=='submit' value='submit'>
</form>
|
And here is one way to pick up the first FieldName, data pair in the second page:
Code: |
var data = new Array();
var flds = new Array();
// gets just sent data
var tmp = document.location.search;
// remove the ?
data = tmp.split("?");
// get all FieldName=data pairs
data = data[1].split("&");
// split first data pair into field & data
flds = data[0].split("=");
// display fieldName & data
alert(flds[0] + "\n" + flds[1]);
|
I will be placing all this in help266.htm to show how it works and it will be up on my http://cs.yrex.com/ site.
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508
|
|
Back to top |
|
 |
|