How to set the focus to a child window without refreshing it?

后端 未结 2 1238
礼貌的吻别
礼貌的吻别 2021-01-14 01:08

I am having a web page which contain four links, each link open a popup window. I am using a common JavaScript function to open popup window, as given below

         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-14 01:31

    For 1 and 2 , you can use this function

    // loads an URL into the popup without reloading it
    function popupnr(mylink, windowname, refocus) {
        // open the window with blank url
        var mywin = window.open('', windowname, 'window attrs here');
    
        // if we just opened the window
        if (mywin.closed || (!mywin.document.URL) || (mywin.document.URL.indexOf("about") == 0)) {
            mywin.location = mylink;
        }
        else if (refocus) {
            mywin.focus();
        }
    
        // return the window
        return mywin;
    }
    
    1. You cant refer a child window by its name. There is no window.children. You need to call window.open to get a reference.

    2. Yes you can. But u need to use the same window name while calling window.open

提交回复
热议问题