如何在php中打开一个新窗口后转到父窗口

时间:2016-03-30 12:07:21

标签: javascript html

<form onsubmit="window
     .open('paper.php?start_t=yes&pass_sub_id=<?php echo $qr1;?>',
            'print_popup',
            'width=1000,height=800');">

它将打开一个新窗口,当我点击新打开的窗口上的提交时,它将返回到父页面并打开一个网址。

1 个答案:

答案 0 :(得分:0)

此代码打开一个新窗口并在事先调用事件之前调用XMLHttpRequest并带来新内容......

<!DOCTYPE html>
<html>
<body>
 <p>Click the button to open the new window.</p>
 <button onclick="myFunction()">Try it</button>
 <script>
    function myFunction() {
        var newWindow = window.open("popup.htm", "popup", "width=200, height=100");
        console.log("LOG 1:"+newWindow.location.href);
        newWindow.addEventListener("beforeunload",function(event){
            loadNew();
        }, true);
    }
    function loadNew(){
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementsByTagName("html")[0].innerHTML = xhttp.responseText;
            }
        };
        xhttp.open("GET", "popup.htm", true);
        xhttp.send();
    }
  </script>
 </body>
</html>

我是这样做的,因为window.location.href="newLocation.html"对我不起作用......