Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
window.opener引用在Java 1.7.0_04-b20中的小程序重定向期间更改,但在1.7.0_03-b05中没有更改_Java_Javascript_Firefox_Applet_Popup - Fatal编程技术网

window.opener引用在Java 1.7.0_04-b20中的小程序重定向期间更改,但在1.7.0_03-b05中没有更改

window.opener引用在Java 1.7.0_04-b20中的小程序重定向期间更改,但在1.7.0_03-b05中没有更改,java,javascript,firefox,applet,popup,Java,Javascript,Firefox,Applet,Popup,我遇到了javascript属性window.opener(它保留了对打开弹出窗口的窗口的引用)以及小程序中的重定向问题。每当小程序中发生重定向时,window.opener将更改为当前弹出窗口。更奇怪的是,最近的一次java更新引入了这一变化:这不是发生在Java1.7.0\u03-b05上,而是发生在Java1.7.0\u04-b20上。现在,这可能是一些异国情调的用例,但我仍然想知道这种改变是否是有意的 为了弄清这一点,我编写了一个小测试来演示有问题的行为。可以找到HTML站点。它只在Fi

我遇到了javascript属性
window.opener
(它保留了对打开弹出窗口的窗口的引用)以及小程序中的重定向问题。每当小程序中发生重定向时,
window.opener
将更改为当前弹出窗口。更奇怪的是,最近的一次java更新引入了这一变化:这不是发生在
Java1.7.0\u03-b05
上,而是发生在
Java1.7.0\u04-b20
上。现在,这可能是一些异国情调的用例,但我仍然想知道这种改变是否是有意的

为了弄清这一点,我编写了一个小测试来演示有问题的行为。可以找到HTML站点。它只在Firefox中工作(这对我的用例来说是可以的)

  • index.html
    页面包含以下javascript:

    window.name = "index.html";
    
    function open_new_window() {
        window.open('applet.html', 'applet.html', 'width=1050,height=680,scrollbars=yes,status=yes').focus();
        return false;
    }
    
    window.name = "HelloWorldApplet.html";
    
    alert("opener is now: "+window.opener.name);
    
    function on_load() {
        alert("changing bgcolor of opener to red");
        window.opener.document.body.style.background='red';
    }
    
    window.name = "redirect.html";
    
    alert("opener is now: "+window.opener.name);
    function on_load() {
        alert("changing bgcolor of opener to green");
        window.opener.document.body.style.background='green';
    }
    
    我将windows名称设置为“index.html”(用于识别目的),并提供了一个在弹出窗口中打开applet.html的函数。 它还包含一个调用此函数的链接:

    <a href="#" onclick="open_new_window(); return false;">open applet.html in new                
    window</a>
    
    我将这个弹出窗口的window.name设置为“applet.html”(用于识别),并提醒当前的
    window.opener.name
    。当body触发onload事件时,我将openers背景颜色更改为红色

    此外,此页面还包含一个小程序,该小程序有一个按钮,可触发重定向到
    redirect.html

    import java.applet.Applet;
    import java.awt.Button;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    public class HelloWorldApplet extends Applet implements ActionListener {
    
        Button redirectButton;
    
        @Override
        public void init() {
            super.init();
    
            setLayout(new FlowLayout());
            redirectButton = new Button("Redirect now!");
            add(redirectButton);
    
            redirectButton.addActionListener(this);
        }
    
        @Override
        public void actionPerformed(ActionEvent ae) {
            try {
                this.getAppletContext().showDocument(new URL(this.getDocumentBase(), "redirect.html"), "_self");
            } catch (MalformedURLException ex) {
                Logger.getLogger(HelloWorldApplet.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    
  • 单击小程序中的按钮后,
    redirect.html
    将在同一弹出窗口中打开。此页面包含以下javascript:

    window.name = "index.html";
    
    function open_new_window() {
        window.open('applet.html', 'applet.html', 'width=1050,height=680,scrollbars=yes,status=yes').focus();
        return false;
    }
    
    window.name = "HelloWorldApplet.html";
    
    alert("opener is now: "+window.opener.name);
    
    function on_load() {
        alert("changing bgcolor of opener to red");
        window.opener.document.body.style.background='red';
    }
    
    window.name = "redirect.html";
    
    alert("opener is now: "+window.opener.name);
    function on_load() {
        alert("changing bgcolor of opener to green");
        window.opener.document.body.style.background='green';
    }
    
    我将这个弹出窗口的window.name设置为“redirect.html”(用于识别),并提醒当前的
    window.opener.name
    。当主体触发onload事件时,我将打开器的背景颜色更改为绿色

  • 使用
    java 1.7.0_03-b5时,会发生以下情况:

  • 单击
    index.html
    中的链接后,将在弹出窗口中打开
    applet.html
    。此警报将
    index.html
    显示为开场白名称。然后,开瓶器的背景色变为红色
  • 单击小程序中的按钮后,
    redirect.html
    将在同一窗口中打开。此警报将
    index.html
    显示为开场白名称。然后,开瓶器的背景色变为绿色
  • 到目前为止还不错。。。但是使用
    java 1.7.0_04-b20时会发生以下情况:

  • 单击
    index.html
    中的链接后,将在弹出窗口中打开
    applet.html
    。此警报将
    index.html
    显示为开场白名称。然后,开瓶器的背景色变为红色
  • 单击小程序中的按钮后,
    redirect.html
    将在同一窗口中打开。此警报将“redirect.html”显示为开场白名称。然后,开瓶器的背景色(现在是弹出窗口!)变为绿色
  • 因此,小程序似乎通过
    this.getAppletContext().showDocument(新URL(this.getDocumentBase(),“redirect.html”),“_self”)发出重定向将window.opener属性更改为它在中更改URL的窗口

    如果您能深入了解这种行为可能发生变化的原因,或者您能想象解决此问题的方法,我将不胜感激


    非常感谢您抽出时间

    您的帖子让我明白,我不是这里唯一一个发疯的人。我相信这是新java版本中的一个bug

    我只是在弹出页面中添加了以下javascript:

    var parentWin=window.opener


    然后,当我需要打电话给家长时,我使用parentWin。这解决了我的问题。

    考虑改用a。请注意,大多数人不会特别关心另一个applet/JS/browser/JRE/focus-interaction错误或怪癖。此时,顶级小程序应答者能得到的唯一建议如下。别再在多个浏览器窗口里胡闹了。如果你这样做了,痛苦是当之无愧的。安德鲁,谢谢你的评论和“建议”。我希望我能“停止在多个浏览器窗口上撒尿”,但就目前而言,这个决定不在我的掌握之中。“现在这个决定不在我的掌握之中”请向我保证,你正在向做出决定的人收取“最高美元”:(是啊,好像是个虫子!