javascript - 打开一个新窗口检查属性是否在页面的新窗口中
问题描述
我需要帮助,我希望代码执行类似的操作 打开一个新窗口,检查属性是否在页面的新窗口中。检查元素是否在第二个窗口中并将信息返回给第一个窗口
<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>
解决方案
如果您尝试使用其他域打开页面:
您无法通过 javascript 访问其他域窗口/页面 html。您可以使用诸如 ..GetResponse.. 之类的想法从服务器端获取 html。
最好使用例如 jQuery 对话框而不是
window.open-dialog
( https://jqueryui.com/dialog/ ) 进行相同域上的交互
推荐阅读
- sql - 双倍或三倍时间戳问题
- python - 如何在此代码中发现“列表索引超出范围”错误?
- python - python中是否有一个函数可以帮助我获取网页中隐藏的html数据?
- python-3.x - 硒元素不可点击。消息:将目标移出边界(会话信息:chrome=77.0.3865.90)
- c# - 具有依赖注入的 Entity Framework Core 是如何处理的?
- javascript - 为什么 Typescript 不鼓励将值设置为 null?
- c++ - 使用 MFC 读取文件
- python - 如何在 aiohttp 中设置查询处理程序
- laravel - 如何在查询中包含另一个表中的列?
- mysql - 在多个表中更新,设置多个值