首页 > 解决方案 > 打开一个新窗口检查属性是否在页面的新窗口中

问题描述

我需要帮助,我希望代码执行类似的操作 打开一个新窗口,检查属性是否在页面的新窗口中。检查元素是否在第二个窗口中并将信息返回给第一个窗口

<body>
    <label><input type="checkbox" checked>Regulamin</label>
<br>
<button onclick="openWindow()">Otwiera okno 1</button>
<br>
<button onclick="element()">Sprawdz element</button>
<br>
<button onclick="wykrywanie()">Sprawdz wykrywanie w oknie </button>		
<script>
function openWindow(){
    var win = window.open('https://www.wp.pl/', '1366002941508',  'width=700,height=500,left=375,top=330');
    setTimeout(function(){
        win.close()
    }, 3000);
    return false;
}
function element(){
	if ($("input").is(':checked')) {
	alert('kliknięto w like');
	} else{ alert('nie klik w like');
}
}
function wykrywanie(){
    var newWindow = window.open('https://www.wp.pl/', '1366002941508',  'width=700,height=500,left=375,top=330');
newWindow.document.body.innerHTML = "<b>mateusztoja</b>";
newWindow.document.close();
    return false;
	}	
</script>
</body>

标签: javascripthtml

解决方案


  1. 如果您尝试使用其他域打开页面:

    您无法通过 javascript 访问其他域窗口/页面 html。您可以使用诸如 ..GetResponse.. 之类的想法从服务器端获取 html。

  2. 最好使用例如 jQuery 对话框而不是window.open-dialog( https://jqueryui.com/dialog/ ) 进行相同域上的交互


推荐阅读