Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    opener.object method() from a popup don't work with IE

    Some comment about the code:
    -This code work with Firefox/Mozilla
    -The Source page contain all Javascript code.
    -If the object is created in the source page, it work with IE.
    -The problem is the line: var test = new opener.window.popup()(object can't be instancied??).
    -The popup object with the function reload() must change the value of a span in opener.window.


    Source Page Code:

    <html>
    <head>
    <script language="javascript" type="text/javascript">
    /*Function to open a center POPUP*/
    function open_center_popup(url,name,width,height,options)
    {
    var top=(screen.height-height)/2;
    var left=(screen.width-width)/2;
    window.open(url,name,"top="+top+",left="+left+",width="+width+",height="+height+","+options);
    }
    /****************************************************************************************/
    /*POPUP Object*/
    function popup() {
    this.id = "99999";
    this.txt = "ZZZZZZ";
    this.reload = function(){
    field = document.getElementById(this.id);
    field.innerHTML = this.txt;
    }
    this.talk = function() {
    document.write( "TEST" );
    }
    }
    popup.prototype.setId = function(id) {
    this.id = id;
    }
    popup.prototype.setText = function(txt) {
    this.txt = txt;
    }
    /*End POPUP object*/
    /******************************************************************************************/
    </script>
    </head>
    <body>
    <script language="javascript" type="text/javascript">
    var test = new popup();
    var test2 = new popup();
    document.write(" Init Value for Id: " + test.id + " Init Value for Txt: " + test.txt);
    test.setId("textarea");
    test.setText("Chercq");
    document.write("</br> Value after Set for Id: " + test.id + " Value after Set for Txt: " + test.txt + "</br>");
    </script>

    <span id="textarea">DefaultValue</span>
    <a href='#'onClick="javascript:test.reload()">Change</a>
    </br>
    <a href='#'onClick="open_center_popup('popupB.html','popup',590,475,'scrollbars=yes')">GoToPopup</a>
    </body>
    </html>


    Popup source Page



    <html>
    <head>
    <script language="javascript" type="text/javascript">
    </script>
    </head>
    <body>
    <script language="javascript" type="text/javascript">
    var test = new opener.window.popup();/*Here the object is create with a method from source page*/
    document.write(" Init Value for Id: " + test.id + " Init Value for Txt: " + test.txt);
    test.setId("textarea");
    test.setText("TXTVALUE");
    document.write("</br> Value after Set for Id: " + test.id + " Value after Set for Txt: " + test.txt + "</br>");
    </script>

    <a href='#'onClick="javascript:test.reload();window.close();">Change</a>
    </body>
    </html>


    Thx for help.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,950
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Maybe that's just the limitation of IE not being able to instantiate a constructor located in the opener window. I think making it OO-based is an overkill if you only want to set the value of a span in the opener window.

    opener:
    Code:
    function setValue(id, value){
      document.getElementById(id).innerHTML = value;
    }
    popup:
    Code:
    if (opener && !opener.closed && opener.setValue){
      opener.setValue("textarea", "TXTVALUE");
    }
    Isn't that enough?

  • #3
    New to the CF scene
    Join Date
    May 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv
    Maybe that's just the limitation of IE not being able to instantiate a constructor located in the opener window.
    Thx for this explication...

    Your solution was my first but i would like to use a object and let the javascript code in opener window...

    finaly i put the popup object code in popup page.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,950
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Quote Originally Posted by landril
    finaly i put the popup object code in popup page.
    That defeats the purpose of re-using codes. I assume you have many popups instantiating a popup object, the reason why you initially have a constructor in the opener. If you put the popup constructor in every popup pages that need it, then maintaining it is difficult. My simple solution I think is better. Sometimes, a simple and straightforward solution is better than an elegant one.

  • #5
    New to the CF scene
    Join Date
    May 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Finally i have the solution, instantiate the object in opener window.

    Opener window
    Code:
    <html>
    <head>
    <script language="javascript" type="text/javascript">
    /*Function to open a center POPUP*/
    function open_center_popup(url,name,width,height,options) 
    {
    	var top=(screen.height-height)/2;
    	var left=(screen.width-width)/2;
    	window.open(url,name,"top="+top+",left="+left+",width="+width+",height="+height+","+options);
    }
    /****************************************************************************************/
    /*POPUP Object*/
    function popup() {
    	/*The id of the span*/
    	this.idTxt = "unseted";
    	/*The id of the hidden form*/
    	this.idForm = "unseted";
    	/*The value to set for the span and the form*/
    	this.value = "defaulttxt";
    	/*function who set dynamically the form and the span with the selected value (=this.value) */ 
    	this.reload = function(){
    		fieldTxt = document.getElementById(this.idTxt);
    		fieldTxt.innerHTML = this.value;
    		fieldForm = document.getElementById(this.idForm);
    		fieldForm.innerHTML = this.value;
    	}
    }
    /*Method to set idTxt*/
    popup.prototype.setIdTxt = function(idTxt) {
    	this.idTxt = idTxt;
    }
    /*Method to set idForm*/
    popup.prototype.setIdForm = function(idForm) {
    	this.idForm = idForm;
    }
    /*Method to set txt*/
    popup.prototype.setValue = function(value) {
    	this.value = value;
    }
    /*End POPUP object*/
    /******************************************************************************************/	
    </script>
    </head>
    <body>
    	<script language="javascript" type="text/javascript">
    	var nom = new popup();
    	var test = new popup();
    	</script>
    	<form>
    		<table border=1>
    			<tr><td>Nom:</td><td><span id="textarea2">Dupont</span></td><td><input type="hidden" id="formarea2" value="Dupont"></td></tr>
    			<tr><td>Localité:</td><td><span id="textarea">Bruxelles</span></td><td><input type="hidden" id="formarea" value="Bruxelles"></td></tr>
    		</table>
    	</form>	
    	</br>
    	<a href='#'onClick="open_center_popup('popupB.html','popup',680,475,'scrollbars=yes')">GoToPopup</a>
    </body>
    </html>
    Popup

    Code:
    <a href='#'onClick="window.close();javascript:opener.nom.setIdTxt('textarea2');javascript:opener.nom.setIdForm('formarea2');javascript:opener.nom.setValue('Bouvrat');javascript:opener.nom.reload();">Change nom (Bouvrat)</a></br>

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,950
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Glad you fixed it yourself.

    But isn't it safer to set the opener fields first before closing the popup?
    And you should check if the opener it it's closed or not to avoid error.
    Code:
    function closeIt(){
      if (opener && !opener.closed && opener.nom)  {   
         opener.nom.setIdTxt('textarea2');
         opener.nom.setIdForm('formarea2');
         opener.nom.setValue('Bouvrat');
         opener.nom.reload();
      }
      window.close();
      return false;
    }
    ...
    <a href='#' onClick="return closeIt();">Change nom (Bouvrat)</a>


  •  

    Posting Permissions

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