Avatar billede fredand Forsker
19. april 2001 - 13:28 Der er 6 kommentarer og
1 løsning

Access element between diffrent windows!

Hola!

This might be a bit tricky!

I would like to access, (tags), from one window although the tag is in an other window.
How do you mean, you might said, this is how:

<!--HTML FILE 1-->
<html>
<head>
</head>
<body>
  <h1>Fönster 1</h1>
  <input type=\"button\" name=\"b1\" value=\"open\">
  <input type=\"button\" name=\"b2\" value=\"change\">
  <script type=\"text/JScript.Encode\" src=\"javscriptfile.js\"></script>
</body>
</html>


//javscriptfile.js
function openNewWindow()
{
  window.open(\"sökväg till HTML FIL 2\",\'opensmall\',\'width=600,height=400,toolbar=no\');
}

function changeElement()
{
  window.document.all.element.innerText == \"Hola amigo!\";
}

window.document.all.b1.onclick = openNewWindow;
window.document.all.b2.onclick = changeElement;


<!--HTML FIL 2-->
<html>
<head>
</head>
<body>
  <h1>Fönster 2</h1>
  <span id=\"element\"></span>
  <script type=\"text/JScript.Encode\" src=\"javscriptfilen.js\"></script>
</body>
</html>

The script is supposed to change the innerText at the <span>-tag in Window 2 from window 1, when some one clicks button b2.

I\'m pretty sure that this doesn\'t work, but it would be great if some one know how, and could explain it to me!

Best Regards
Fredrik

Fredrik
Avatar billede nute Nybegynder
19. april 2001 - 13:30 #1
you can accsess fields in the opened window by using

opener.formname.fieldname...

and from the opened window to the \"parent\" window by using

parent.formname....

*/nute
Avatar billede fredand Forsker
19. april 2001 - 14:08 #2
Hola!

I just tried to use your suggetstions but I must done it wrong:
//window.document.all.element.innerText == \"Hej på dig\";
    //window.document.all.opener.element.innerText == \"Hej på dig\";
    //opener.opensmall.element.innerText == \"Hej på dig\";
    window.document.all.opener.opensmall.element.innerText == \"Hej på dig\";

None of this seems to work!

Perhaps you could give me some more code exampels.

Regards

Fredrik
Avatar billede jakoba Nybegynder
19. april 2001 - 19:53 #3
from an opened window back to the windov or frame that opened it:

opener.your_normal_name

from the window that opened to the one that was opened:

frames.windowname.your_normal_name
or (preferable):
vinVariable.your_normal_name

where winVariable var the variable set during your call to window.open (eg: WinVariable = window.open( url, \'windovname\', specs ) )

between frames you use the parent pointer.

from one frame to another
parent.framename.your_normal_name
where framename is defined with at  name=\"framename\"  parameter in the <fram command in the frameset file.

best JakobA


Avatar billede fredand Forsker
19. april 2001 - 20:29 #4
Hola!

I\'m trying this, to change a innerText in an other window, but it wont work any suggestions:

//javscriptfilen.js
var newWindow;
function openNewWindow()
{
    newWindow = window.open(\"http://fredrikand/develop/IP3/lektion8/test8b.html\",\'opensmall\',\'width=600,height=400,toolbar=no\');

    if (newWindow.opener == null)
    {
          newWind.opener = self;
    }

}

function changeElement()
{
    //window.document.all.element.innerText == \"Hej på dig\";
    //window.document.all.opener.element.innerText == \"Hej på dig\";
    //opener.opensmall.element.innerText == \"Hej på dig\";
    //newWindow.document.element.innerText == \"Hej på dig\";
    //window.document.all.h.innerText == \"Hej på dig\";
    newWindow.document.all.d.innerText == \"Hej på dig\";
    window.document.all.t.innerText = \'Här är ett helt annat innehåll!\';
}

window.document.all.b1.onclick = openNewWindow;
window.document.all.b2.onclick = changeElement;



<!--HTML FIL 1-->
<html>
<head>
</head>
<body>
    <h1 id=\"h\">Fönster 1</h1>
    <input type=\"button\" name=\"b1\" value=\"open\">
    <input type=\"button\" name=\"b2\" value=\"change\">
    <div id=\"t\">Här är ett visst text-innehåll!</div>
    <script type=\"text/JScript.Encode\" src=\"js/test.js\"></script>
</body>
</html>

<!--HTML FIL 2-->
<html>
<head>
</head>
<body>
    <h1>Fönster 2</h1>
    <h3 id=\"h3\">hej</h3>
    <div id=\"d\">Här är ett visst text-innehåll!</div>
    <script type=\"text/JScript.Encode\" src=\"js/test.js\"></script>
</body>
</html>

Best Regards
Fredrik

Avatar billede jakoba Nybegynder
19. april 2001 - 21:30 #5
Jeg believe that:
    newWindow.document.all.d.innerText == \"Hej på dig\";
vill work if you change the == (comparison operator) to a = (assignment operator).
    newWindow.document.all.d.innerText = \"Hej på dig\";

It seems that you are not entirely sure of how a division in the file should be addressed. In a situation like that when there is more than one uncertainty it is always preferable to try to solve them seperately.

to become CERTAIN about the the adressing of the division you might add the following code in HTML fil 2 (after the body tag):

<form>
<input type=\'button\' value=\'check div d adress\'
      onclick=\"document.all.d.innerText = \'tekst fra knappen\';\">
</form>

if the content of the div change when the button is pressed You will KNOW that  document.all.d.innerText  is a proper address locally on the page.

best JakobA
Avatar billede fredand Forsker
20. april 2001 - 08:51 #6
Hola Amigos!

Thanks for all your help!
I must have been so blind, how could I miss to use the == (comparison operator) insted of the = (assignment operator).

Now this works perfect thanks to you guys!
Avatar billede fredand Forsker
20. april 2001 - 08:52 #7
Thanks to both Jakob and Nute!

Best Regards
Fredrik
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester