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 8 of 8
  1. #1
    New Coder
    Join Date
    Nov 2012
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    window on the fly

    Hello!

    I want to create a new window, from within a function, with some features.
    But in the new page a design here, i must call the function confirm(). My code doesn't do anything and i really have no idea if is correct.

    This is it:


    Code:
    <script type="text/javascript">
    var wind;
    function noua()
    {
    wind=window.open("","Fereastra noua", "left=50,top=50,width=600,height=500,toolbar=no,scrollbars=no,resizable=no");
    wind.document.write("<html><head><title>Fereastra noua</title></head><body>");
    wind.document.write("<p>Screen Coordinates:<br>");
    wind.document.write("ScreenX: "+wind.screenX+"<br>");
    wind.document.write("ScreenY: "+wind.screenY+"</p>");
    wind.document.write("<p>Browser Details:<br>");
    wind.document.write("Browser name: "+navigator.appName+"<br>");
    wind.document.write("Browser version: "+parseFloat(navigator.appVersion)+"<br>");
    wind.document.write("Platform: "+navigator.platform+"</p>");
    wind.document.write("<div><input type='button' id='b' value='Esti sigur?' onclick='confirmare()'></div>");
    }
    
    function confirmare()
    {
    var r=confirm("alege");
    if(r==true)
       {alert('yes');}
    else
       {alert('no');}   
    }
       
    </script>

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    It's because confirmare is in the parent window, not the child window.

    You can either include the function in the child window, or access the function in the parent window by using "window.opener.confirmare()".
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    New Coder
    Join Date
    Nov 2012
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you very much. Now it works.

  • #4
    New Coder
    Join Date
    Nov 2012
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Although, i would have one more question. How could i include the function in the child window and open there a new web page?

  • #5
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Add the function to the wind.document.write would be one way. But document.write is ancient and shouldn't be used, really.

    Best to create another document with all the code in place, then call that file in the window.open command. IE "window.open('document.html','Fereastra noua',' attributes')".
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #6
    New Coder
    Join Date
    Nov 2012
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well yeah, but then screenX and screenY won't have the same values if i write the code in a new document.

  • #7
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Instead of wind.screenX from the parent, have you tried window.screenX in the child?
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,456
    Thanks
    0
    Thanked 632 Times in 622 Posts
    Don't forget to remove the debugging alert() statements before your page goes live.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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