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

后端 未结 2 1186
礼貌的吻别
礼貌的吻别 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:14

    I think what you want for 1 and 2 is:

    if(!targetWin)
    {
        var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, 
            directories=no, status=no, menubar=no, scrollbars=Yes, resizable=no, 
            copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
    }
    targetWin.focus();
    
    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题