Answer the question
In order to leave comments, you need to log in
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
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>
If the task was described in more detail (what you want and why), I think someone would suggest a solution without crutches.
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
window.parent from a doc inside an iframe refers to the window containing that iframe.
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.
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question