Results 1 to 3 of 3

Thread: window.open() amd window.opener.document. JavaScript Problem in FireFox

  1. #1
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default window.open() amd window.opener.document. JavaScript Problem in FireFox

    Hi All,

    Firstly I know this issue has been addresses a lot already but as a newbie to HTML and Web Development I am unable to get the idea.

    according to documentations and solutions proposed on different forums a popup or child window can be only closed using window.close() if it is opened via window.open() function.

    Below is my code for opening the popup:

    Code:
    function getPorts(form){
                var odfid = form.cmbodf.options[form.cmbodf.options.selectedIndex].value; 
               window.open('odfPorts.php?id='+odfid,'popuppage','width=515,titlebar=0,title=Select ODF,toolbar=0,resizable=0,scrollbars=no,height=500,top=150,left=500');
             }
    hence I am using window.open() to open window, ideally it should be closed using window.close().

    Following is my code to close the pop up(it is validating some check boxes status and passing values to parent form and then is supposed to be closed)

    Code:
    function CheckCheckboxes(form, ot){
        var elLength = form.elements.length;
        var portNo=new Array(2);
        var a=0;
        if (ot==1){
            for (i=0; i<elLength; i++)
            {
                var type = form.elements[i].type;
                if ((type=="checkbox" && form.elements[i].checked) && !(form.elements[i].disabled)){
                portNo[a]=i+1;
                a++;         
                }
            }               
        }else{
            for (i=0; i<elLength; i++){
                var type = form.elements[i].type;
                if ((type=="checkbox" && form.elements[i].checked) && !(form.elements[i].disabled)){
                    portNo[0]=i+1.1;
                    portNo[1]=i+1.2;
                    a=2;
                }
            }
        }
        alert('function called');
        if (a<2) {
            alert ("Please Select Ports");
        }else{
            alert('function called11111111111111111'); 
       /*executed successfully */
    /*NONE OF THE BELOW CODE IS BEING EXECUTED IN FIREFOX*/
            window.opener.document.forms[0].getElementById('P1').value =portNo[0];
            window.opener.document.forms[0].getElementById('P2').value =portNo[1];
            window.opener.document.forms[0].getElementById('P11').value =portNo[0];
            window.opener.document.forms[0].getElementById('P21').value =portNo[1];
    /* I found following three solutions on internet and tried all those but none of them working*/     
    /* 1 */
    window.setTimeout("window.close()", 1) 
    /* 2 */
        window.close(); /* tested not working*/
    /* 3 */    
    var win=window.open("","_self");
       win.close();
        }
    }
    Moreover I found some where to set dom.allow_scripts_to_close_windows, can anyone guide me how to set this one.

    For reference following is version of my firefox:

    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7 (.NET CLR 3.5.30729)

    I hope I am making a mistake some where.

  2. #2
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi all,

    I found a partial solution to my problem, sharing it here may be helpful to some others.

    for accessing my parent window controls i made following changes:
    Original Code:
    Code:
    /*NONE OF THE BELOW CODE IS BEING EXECUTED IN FIREFOX*/
            window.opener.document.forms[0].getElementById('P1').value =portNo[0];
            window.opener.document.forms[0].getElementById('P2').value =portNo[1];
            window.opener.document.forms[0].getElementById('P11').value =portNo[0];
            window.opener.document.forms[0].getElementById('P21').value =portNo[1];
    New Code

    Code:
    self.opener.document.getElementById('P1').value =portNo[0];
            self.opener.document.getElementById('P2').value =portNo[1];
            self.opener.document.getElementById('P11').value =portNo[0];
            self.opener.document.getElementById('P21').value =portNo[1];
    I am still unable to close the child page in Firefox I have tried following solutions:

    1. self.close();
    2. window.setTimeout("window.close()", 1);
    3. window.close();
    4. var win=window.open("","_self");win.close();

  3. #3
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi All,

    my efforts to search the internet more resulted in a solution . sharing it here for for others to find solution.

    I used the below code to close my popup form in Firefox and it worked properly.

    Code:

    Code:
    window.open('','_parent','');         
    window.close();

    regarding dom.allow_scripts_to_close_windows you can change it by going to about:config in your firefox. about:config will show you different settings will show you many options regarding your firefox settings. but this is not adviseable as you may not be able to make sure that every visitor to your page has this setting changed.

    thanks to all who viewed this port and put their time in reading it.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •