父页面中的onclick如何等待子页面的事件后在执行? javascriptframe 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function openwin(element) { var url = "http://localhost/imgonclick.html"; var newWindow = window.open(url,'frame','width=100%,top=0,left=0,status=no');newWindow.onload=function(){ changeImage(element) }} 谢谢这么快就回复我了。我试着改了代码用了 onload,但是点击自页面,主页面没有的图片没有变化。方便起见我用了frameset.麻烦再给我指导一下,谢谢。 index.html (frameset)<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"><HTML> <meta http-equiv="Content-Type" name="viewport" content="text/html, charset=utf-8" width="480" height=100%><HEAD><TITLE>测试</TITLE></HEAD><FRAMESET cols="50%, 50%"> <FRAME name = "main" src="main.html"> <FRAME name="jizi" src="http://www.apple.com/"></FRAMESET></HTML>main.html (主页面)<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head><title>测试</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="mystyle.css"></head><script type="text/javascript">if (window.navigator.standalone) { $(document).on( "click", "a", function (event) { event.preventDefault(); var aurl = $(event.target).attr("href"); if (aurl) { location.href = $(event.target).attr("href"); } else { location.href = this; } } );}var filename = "./some.png";function changeImage(element) { element.setAttribute("src", filename); }function openwin(element) { var url = "http://localhost/~walter/imgonclick.html"; var newWindow = window.open(url,'jizi','width=100%,top=0,left=0,toolbar=no,menubar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no'); newWindow.onload = function() { changeImage(element) }}</script><body><img src="./old.png" width="100%" onclick="openwin(this);" /><img src="./old.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"> <link rel="stylesheet" type="text/css" href="mystyle.css"> <script type="text/javascript"> function choose() { /* document.location.href="jizi_ref.html"; */ self.window.opener.filename = "new.png"; window.opener.close(); } </script> </head><body> <img width='240' src="./new.png" height='auto' width='auto' onclick='choose();'></body></html> iframe 用parentopen 子窗口用openerfunction choose() { /* document.location.href="jizi_ref.html"; */window.parent.changeImage("new.png"); window.parent.close(); } 我测试了用一下,在这个例子中,子页面要用window.opener 来调用父页面的函数和变量。我想可能是因为在index.html中用frameset的缘故。使用frameset是为了照顾我的Iphone浏览器Safari.在主页面中,<img src="./old.png" width="100%" onclick="openwin(this);" /> 中的 this 是指的img整个对象吗?我在子页面中执行changeImage参数中应该没有这个对象。也不知道怎么才能在主页中click点击来触发继续执行那个changeImage. 子页面获取父页面元素直接赋值window.parent.document.getElementById('img_id').src='aaaaaaaaaa.jpg' 非常感谢!window.openert.document.getElementById('img_id').src='aaaaaaaaaa.jpg' 搞定了! 数据中带有换行时,json怎么读取 select 与submit关联 求一个js库 类似于QQ空间图片查看 jsp页面做视频播放,需要代码,这是对外的视频网站,任何客户都可以播放? 跪求:学习javascript和web编程技术的好书籍! 寻找兼职网站美工一名 问一个棘手的问题,大家帮帮忙!高分! 大版主,特别是阿信,进来看! \杠转换问题,急急急急急!!! js如何获取时间范围内的年月 (function(){}()) 和 (function(){})() 的区别 这个错误是什么情况?
function openwin(element) {
var url = "http://localhost/imgonclick.html";
var newWindow = window.open(url,'frame','width=100%,top=0,left=0,status=no');
newWindow.onload=function(){
changeImage(element) }
}
麻烦再给我指导一下,谢谢。
index.html (frameset)<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<HTML>
<meta http-equiv="Content-Type" name="viewport" content="text/html, charset=utf-8" width="480" height=100%>
<HEAD>
<TITLE>测试</TITLE>
</HEAD>
<FRAMESET cols="50%, 50%">
<FRAME name = "main" src="main.html">
<FRAME name="jizi" src="http://www.apple.com/">
</FRAMESET>
</HTML>main.html (主页面)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>测试</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head><script type="text/javascript">
if (window.navigator.standalone) { $(document).on(
"click",
"a",
function (event) {
event.preventDefault();
var aurl = $(event.target).attr("href");
if (aurl) {
location.href = $(event.target).attr("href");
}
else {
location.href = this;
}
}
);
}var filename = "./some.png";function changeImage(element) {
element.setAttribute("src", filename);
}function openwin(element) {
var url = "http://localhost/~walter/imgonclick.html";
var newWindow = window.open(url,'jizi','width=100%,top=0,left=0,toolbar=no,menubar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');
newWindow.onload = function() {
changeImage(element)
}
}
</script>
<body>
<img src="./old.png" width="100%" onclick="openwin(this);" />
<img src="./old.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">
<link rel="stylesheet" type="text/css" href="mystyle.css"> <script type="text/javascript"> function choose() {
/*
document.location.href="jizi_ref.html";
*/
self.window.opener.filename = "new.png";
window.opener.close();
} </script>
</head><body>
<img width='240' src="./new.png" height='auto' width='auto' onclick='choose();'>
</body>
</html>
open 子窗口用opener
function choose() {
/*
document.location.href="jizi_ref.html";
*/
window.parent.changeImage("new.png");
window.parent.close();
}
子页面获取父页面元素直接赋值
window.parent.document.getElementById('img_id').src='aaaaaaaaaa.jpg'