Ответ 1
Вы пробовали это? -
$(win.document).ready(function() {
$(win.document).contents().find("...").doStuff();
});
Этот вопрос обсуждает нечто очень похожее. Дубликат?
Я пытаюсь получить уведомление, когда дочернее окно, которое я открываю, имеет свой документ, загруженный и готовый. Это не работает:
win = window.open(href, 'test', 'width=300, height=400');
win.focus();
$(win.document).ready(function() {
// Ok, the function will reach here but if I try to manipulate the
// DOM it doesn't work unless I use breakpoints
$(this).contents().find("...").doStuff(); // nothing happens
});
Что мне делать?
Вы пробовали это? -
$(win.document).ready(function() {
$(win.document).contents().find("...").doStuff();
});
Этот вопрос обсуждает нечто очень похожее. Дубликат?
У меня была аналогичная проблема, и для меня событие .load в окне действительно работало, но уже не было. Поэтому вы можете попробовать:
win = window.open(href, 'test', 'width=300, height=400');
$(win).load(function() {
$(this).contents().find("...").doStuff();
});
Используйте window.opener
в script на сайте, который вы загружаете и выполняете функцию, определенную в глобальной (!) на первой странице.
Главная страница:
<html>
<head>
<script type="text/javascript">
window.notify = function () {
alert('runned from opened window');
};
window.onload = function() {
document.getElementById('button').addEventListener('click', function() {
window.open('test.html');
}, false);
};
</script>
</head>
<body>
<button id="button">Open window</button>
</body>
Открытая страница:
<html>
<head>
<script type="text/javascript">
window.onload = function() {
window.opener.notify()
};
</script>
</head>
<body>
Popup site
</body>
</html>
Просто добавьте этот код в iframe,
$(document,parent.document).ready(function(){
alert('Done');
});