#javascript #jquery #html
#javascript #jquery #HTML
Вопрос:
В HTML у меня есть две функции: одна — abc с только предупреждением, другая — для создания нового окна с помощью window.open(), заполняемого предопределенной строкой HTML. Я хочу вызвать функцию из родительского HTML. Я пробовал вызывать parent.abc и window.parent.abc. Ни один из них не работает.
<html>
<body>
<button onclick="myfunction()" type="button">A new Window</button>
<script>
var myWindow;
function abc() {
alert("abc");
};
function myfunction() {
var htmlholder = '<!DOCTYPE html>'
'<html>'
'<body>'
'<p>Here is another HTML</p>'
'<button type="button1" onclick="parent.abc()">Call parentabc</button>'
'</body>'
'</html>';
myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write(htmlholder);
};
</script>
</body>
</html>
Комментарии:
1. Всплывающие окна / вкладки есть
opener
, фреймы естьparent
.2. Спасибо за ваше объяснение.
Ответ №1:
Вы должны использовать opener вместо parent . Добавлен скрипач.
function myfunction() {
var htmlholder = '<!DOCTYPE html>'
'<html>'
'<body>'
'<p>Here is another HTML</p>'
'<button type="button1" onclick="opener.abc()">Call parentabc</button>'
'</body>'
'</html>';
myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write(htmlholder);
};