Детское окно имеет свойство, opener
, которое относится к открытому окну. При условии, что они оба из того же происхождения, что ребенок может получить доступ к глобальным переменному на родителе, как это:
opener.globalVariable
Это означает, что он может получить доступ к документу родительского окна, как opener.document
, и поэтому может использовать opener.document.getElementById
или opener.document.querySelector
, чтобы получить на элементах родительского окна.
Пример:
Родительская страница:
<!doctype html>
<html lang="en">
<body>
<input type="text"><input type="button" value="Click me">
<script>
document.querySelector("input[type=text]").value = Math.floor(Math.random() * 10000);
document.querySelector("input[type=button]").addEventListener(
"click",
function() {
var wnd = window.open("popup.html");
},
false
);
</script>
</body>
</html>
Popup страница:
<!doctype html>
<html>
<body>
<script>
var field;
if (!opener) {
display("Not opened as a popup");
} else {
field = opener.document.querySelector("input[type=text]");
display("Value is " + field.value);
}
function display(msg) {
var p = document.createElement('p');
p.innerHTML = msg;
document.body.appendChild(p);
}
</script>
</body>
</html>
Взгляните на этот вопрос: http://stackoverflow.com/questions/7243970/ access-a-window-by-window-name – m69
спасибо за ссылку ..... –