父页面中的onclick怎么等待子页面的事件后在执行
父页面中的onclick如何等待子页面的事件后在执行?
我纯粹是个新手,请教一下,边问边学。
我有两个window,一个是index.html(主窗口), frame(辅助窗口),希望实现:在主窗口index.html点击图片打开新的窗口,然后在新窗口frame接受事件,随后在主窗口改变图片。
我的问题时:如何能在frame窗口返回后,再改变图片?
谢谢!
index.html
imgonclick.html
------解决思路----------------------
子页面获取父页面元素直接赋值
window.parent.document.getElementById('img_id').src='aaaaaaaaaa.jpg'
我纯粹是个新手,请教一下,边问边学。
我有两个window,一个是index.html(主窗口), frame(辅助窗口),希望实现:在主窗口index.html点击图片打开新的窗口,然后在新窗口frame接受事件,随后在主窗口改变图片。
我的问题时:如何能在frame窗口返回后,再改变图片?
谢谢!
index.html
<html>
<head>
<script type="text/javascript">
function changeImage(_element) {
var newpng = "./new.png";
_element.setAttribute("src", newpng);
}
function openwin(element) {
var url = "http://localhost/imgonclick.html";
var newWindow = window.open(url,'frame','width=100%,top=0,left=0,status=no');
changeImage(element)
}
</script>
</head>
<body>
<img id="jizi" src="./tian.png" width="100%" onclick="openwin(this);" />
</body>
</html>
imgonclick.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Type" name="viewport" content="text/html, charset=utf-8, maximum-scale=1">
</head>
<script type="text/javascript">
function choose() {
window.opener.changeImage("something");
}
</script>
<body>
<img width='240' src="./new.png" height='auto' width='auto' onclick='choose();'>
</body>
</html>
------解决思路----------------------
子页面获取父页面元素直接赋值
window.parent.document.getElementById('img_id').src='aaaaaaaaaa.jpg'