解决方案 »

  1.   


    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) }
    }
     
      

  2.   

    谢谢这么快就回复我了。我试着改了代码用了 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>
      

  3.   

    iframe 用parent
    open 子窗口用opener
    function choose() {
        /*
                    document.location.href="jizi_ref.html";
        */
    window.parent.changeImage("new.png");
                    window.parent.close();
                }
      

  4.   

    我测试了用一下,在这个例子中,子页面要用window.opener 来调用父页面的函数和变量。我想可能是因为在index.html中用frameset的缘故。使用frameset是为了照顾我的Iphone浏览器Safari.在主页面中,<img src="./old.png" width="100%"  onclick="openwin(this);" /> 中的 this 是指的img整个对象吗?我在子页面中执行changeImage参数中应该没有这个对象。也不知道怎么才能在主页中click点击来触发继续执行那个changeImage.
      

  5.   


    子页面获取父页面元素直接赋值
    window.parent.document.getElementById('img_id').src='aaaaaaaaaa.jpg'
      

  6.   

    非常感谢!window.openert.document.getElementById('img_id').src='aaaaaaaaaa.jpg' 搞定了!