T
T
TERMIK2011-10-10 21:52:00
JavaScript
TERMIK, 2011-10-10 21:52:00

Don't be foolish, but is it possible in javascript to refer to an element located on another page?

I need to read text from a textarea located on another page. Is it possible? If yes, can you write how to do it?

Answer the question

In order to leave comments, you need to log in

9 answer(s)
K
korvindest, 2011-10-10
@TERMIK

As already mentioned earlier, if you had specified the target more accurately, you would have received an answer with the least number of crutches.
Here is an example of working with a neighboring window. An example (!) is not very perfect, which only demonstrates how it works.
We put both files in one folder and open index.html
This solution has not been tested for cross-browser compatibility, and if necessary, it is better to use a JavaScript framework. Finding elements in another window will also be much easier if you use e.g. jQuery

<!-- index.html-->
<html>
<head>
<title>главное окно</title>
<script type="text/javascript">
var newWin; 
function showText(){
  if (newWin != null){
    alert(newWin.document.getElementById('textinwin').value);
  }
}
</script>
</head>
<body>
<input onclick="newWin = window.open('newwin.html', 'newwin' )" type="button" value="Открыть окно с текстом"></input>

<input onclick="showText();" type="button" value="Получить текст"></input>
</body>
<html>

<!-- newwin.html-->
<html>
<head>
<title>окно с текстом</title>
</head>
<body>
<textarea id="textinwin" rows="3" cols="40" >текст именованного окна</textarea> <!--size="300,300" width="300" height="300"-->
</body>
<html>

I
int03e, 2011-10-10
@int03e

If the task was described in more detail (what you want and why), I think someone would suggest a solution without crutches.

A
Aquahawk, 2011-10-10
@Aquahawk

You can use flash. He knows how to LocalConnection which allows you to communicate with any flash drives on the same computer, even in different browsers. And flash is able to interact with javascript through ExternalInterface. Those. you get a bunch of javascript <-> flash <-> flash <-> javascript. But this requires the presence of special code on both pages, and of course the flash plugin

T
tick, 2011-10-11
@tick

window.parent from a doc inside an iframe refers to the window containing that iframe.

C
CrazySquirrel, 2011-10-10
@CrazySquirrel

By connecting that page as an iframe to this one.

M
markoffko, 2011-10-10
@markoffko

or parse with ajax for example

O
Oleg Yakovenko, 2011-10-10
@Apx

If you open the second window with javascript from the first one, then you have such a feature as window.opener in the second window. This is a reference to the window object of the 1st window. Then everything is clear without words.

R
Regis, 2011-10-10
@Regis

If the domain (more precisely origin) of another page matches the domain of the original page and you actually opened this page through an iframe or window.open, then you can contact.

T
TERMIK, 2011-10-10
@TERMIK

Well, I have this situation: I have 2 iframes. One shows links, and the other shows a *.py file. In my case, I want the innerHTML of the link I clicked to be passed to another frame.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question