• chrome不支持对opener方法的调用?


    自从开始做Web开发后,我就经常在不同的浏览器间换来换去,目前主要使用四种浏览器,分别是IE、Firefox、Chrome和Safari,这四种浏览器各有千秋,说不上谁最好,如今开发的网站,我都会用这四种浏览器测试下效果。最近做一个页面需要用到opener的方法进行调用,我把代码精简了一下,这是主页面main.htm:

    <!DOCTYPE html>
    <html>
    <head>
    <title>Main</title>
    <script>
    function remote() {
        win2 = window.open("remote.htm", "");
    }
    
    function RemoteCallTest() {
        document.getElementById("text-test").innerHTML = "I am called by Remote.";
    }
    </script>
    </head>
    <body>
    <form>
    <input type="button" value="Open Window" onClick="remote()">
    </form>
    <span id="text-test">I am not called.</span>
    </body>
    </html>

    这是要打开的页面remote.htm:

    <!DOCTYPE html>
    <html>
    <head>
    <title>Remote</title>
    </head>
    <body>
    <p>
    <a href="javascript:window.opener.RemoteCallTest()">Call Test</a>
    </p>
    </body>
    </html>

    打开的页面会回调主页面的一个方法,可以来做一个局部刷新什么的。我直接用前面提到的四大浏览器打开main.htm进行测试,发觉Firefox,Safari很顺利通过,而IE则出现一个警告,点“允许”后也通过了,而Chrome却不行,十分奇怪。后来考虑:是否因为浏览器出自于安全的原因禁止了这种调用?于是查看Chrome的设置,却也没发现相关的选项。后来考虑到是不是因为直接打开本地文件而不是打开网站的缘故?我创建了一个简单的MVC程序,调试了一下后发觉居然可以了。代码太简单,上面的改一改就行了,就不贴了。

  • 相关阅读:
    机器学习之朴素贝叶斯法
    机器学习之支持向量机(Support Vector Machine)
    梯度下降(Gradient Descent)
    Error #include nested too deeply
    error while loading shared libraries: libXXX.so.x: cannot open shared object file: No such file or directory .
    ubuntu su Authentication failure
    Log4cplus使用
    passing ‘const ’ as ‘this’ argument of ‘’ discards qualifiers 错误处理
    select()函数 timval问题
    ICE——1.Printer
  • 原文地址:https://www.cnblogs.com/guogangj/p/2729614.html
Copyright © 2020-2023  润新知