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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    New Coder
    Join Date
    Jun 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    function openWindow() question

    I am using "function openWindow() to open three seperate, same sized page/windows.

    I had no problems using this method opening two page/windows but when i added the third, the page/window "events_btn_03.html" will not open, instead page/window "events_btn_04.html opens. this happens eventho each of these pages are named seperately & uploaded to the server as such.

    the file name for each page/window is different: events_btn_02.html, events_btn_03.html, events_btn_04.html, but the function only opens the 02 & 04 page/window.

    here is the code in the homepage (http://www.chevelles.net/oregon/) where the first link (events button) begins:

    function openWindow(file,name) {
    if (screen) {
    var topPos = screen.height /2 -240;
    var leftPos = screen.width /2 -200;
    }
    var newWin = window.open(file,name,'width=200,height=500,left='+leftPos+',top='+topPos+''); newWin.focus();

    • this leads to a secondary page/window that has link buttons for the years 2002, 03, & 04, the code here is:

    <script language="javascript"><!--
    function openWindow() {
    if (screen) {
    var topPos = screen.height /2 -250;
    var leftPos = screen.width /2 -100;
    }
    var newWin = window.open('events_btn_02.html','02events','width=200,height=500,left='+leftPos+',top='+topPos+'');
    newWin.focus();
    }
    // -->
    </script>

    <script language="javascript"><!--
    function newWindow() {
    if (screen) {
    var topPos = screen.height /2 -250;
    var leftPos = screen.width /2 -100;
    }
    var newWin = window.open('events_btn_03.html','03events','width=200,height=500,left='+leftPos+',top='+topPos+'');
    newWin.focus();
    }
    // -->
    </script>

    <script language="javascript"><!--
    function newWindow() {
    if (screen) {
    var topPos = screen.height /2 -250;
    var leftPos = screen.width /2 -100;
    }
    var newWin = window.open('events_btn_04.html','04events','width=200,height=500,left='+leftPos+',top='+topPos+'');
    newWin.focus();
    }
    // -->
    </script>

    • the function code in the "events_btn_03.html" page is:

    function openWindow() {
    if (screen) {
    var topPos = screen.height /2 -250;
    var leftPos = screen.width /2 -100;
    }
    var newWin = window.open('events_btn_03','03events','width=200,height=500,left='+leftPos+',top='+topPos+'');
    newWin.focus();
    }
    // -->
    </script>


    thank you for any suggestions or solutions:
    james
    800-875-4276 PST

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It looks like your second page is in error, you've taken a script (the openWindow script), modified it to not use parameters like it does on your original page and then inserted a second copy of that script on the page using the same name altering the replaced parameters again.

    I suggest you replace both of those adulterated copies of the original script with the original script again and then fix the calls to the original script to supply the URL and window names again. Note that if you want separate windows to open make sure you provide unique window names, if you want whichever link is clicked to open in the same window, use the same window name in your calls to the openWindow function.

    Looking at your website I see the function is present but it isn't even called on your homepage so I sense you've got a real disconnect here in understanding how that script even works and how to use it.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Last edited by jamescover; 07-16-2004 at 07:22 AM.
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry, I didn't see the focus bit...:


    <script>
    <!--

    function newWin(url,winName,props){
    var myWin = window.open(url,winName,"width=400,height=400,top="+((screen.height-400)/2)+",left="+((screen.width-400)/2));
    myWin.focus();
    }


    //-->
    </script>

    <a href="javascript:newWin('events_btn_02.html','win1','props');void(0);">Open New Window</a>

    <a href="javascript:newWin('events_btn_03.html','win2','props');void(0);">Open New Window</a>

    <a href="javascript:newWin('events_btn_04.html','win3','props');void(0);">Open New Window</a>




    http://www.ekigroup.com/javascript/winGen.html


    -james
    Last edited by jamescover; 07-16-2004 at 07:39 AM.
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #5
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts


    This one is more practical for multiple windows--values defined in the handlers...


    <script>
    <!--

    function newWin(picName,winName,w,h,top,left){

    var largePic = window.open(picName,winName,'width='+w+',height='+h+',top='+((screen.height-h)/2)+',left='+((screen.width-w)/2));

    }

    //-->
    </script>

    <a href="javascript:newWin('http://www.yourDomain.com/yourPage.html','myWin','300','300','top','left');void(0);">Open New Window</a>



    -james
    Last edited by jamescover; 07-16-2004 at 07:59 AM.
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #6
    Regular Coder
    Join Date
    Dec 2003
    Location
    America
    Posts
    544
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's what i suggest:

    Code:
    function launch_Pad( addy, title, features )
    {
    var lion;
    
    lion= window.open( addy, title, features )
    
    lion.focus();
    }
    All of the above creates a real basic template that can be reused as many times as you like. That's the beauty of variables, and functions.

    If you need to call the above, or to actually activate the above, you would do something very similar to the below:

    Code:
    <a href="#" onclick="launch_Pad( 'something.html' ,'somethingtitle' , 'top=200px,left=300,height=200px,width=300px' )";> Link_One </a>
    <br>
    <a href="#" onclick="launch_Pad( 'anothersomething.html' ,'secondtitle' , 'top=200px,left=300,height=200px,width=300px' )";> Link_Two </a>
    <br>
    <a href="#" onclick="launch_Pad( '3rdsomething.html' ,'3rdTitletitle' , 'top=200px,left=300,height=200px,width=300px' )";> Link_Three </a>
    <br>
    I will presume that the above makes sense to you?

    How it works is real simple: you create a function to seperate a certain number of commands from the rest of the page, if you will. With the function, you create 3 variables that are basically understood as parameters, or arguments, but they are essentially, storage boxes for the holding, or housing, of content, or what is termed values. The difference between a parameter, and a variable is that you dont use the key word var when you declare a parameter. But over, and beyond this, they are a lot a like.

    At any rate, once you have your local variable inside your function, you define your variable, so in this sense, we say lion=window.open(). We do this so that we can use the variable for the application, or the accessing of additional methods, or properties. But notice how the open() method has what i would like to call a clamp, since through the clamp, the method can hold additional data. This is why we have, lion=window.open(addy, title, features). All we have done is pass the variables from the function launch_pad() onto the open() method, and bingo, you have now a means by which you can send data to its desired location.

    At any rate, we simply pass the paramters of the function, unto the open() method, and wola, you have now a practical little tool by which you can create individual pop-ups. Since each time you call a function, the parameters of that function will contain different pieces of data, or as was stated, values, there's no need to worry about whether or not the function will launch the same window. As long as the values of the parameters are different, you should get different windows. Thus, although you may have a single function, it can be used like 10 different times, for like 10 different pop-ups.

    Does any of this make sense to you?
    Last edited by SpiritualStorms; 07-16-2004 at 06:59 AM.
    LovesWar

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Using functions is nice but not in the case of that launch_Pad example. No offense meant, but it looks like overkill to use a function.

    Your launch_Pad function is almost just a duplicate of window.open. The arguments are the same and you only have window.open inside the function.

    <a href="#" onclick="launch_Pad( 'something.html' ,'somethingtitle' , 'top=200px,left=300,height=200px,width=300px' )";> Link_One </a>

    <a href="#" onclick="window.open( 'something.html' ,'somethingtitle' , 'top=200px,left=300,height=200px,width=300px' )";> Link_One </a>

    Both achieve the same effect, so the latter is better since you don't have the extra function. If you want to focus to the opened window, you can put it like this:

    <a href="#" onclick="window.open( 'something.html' ,'somethingtitle' , 'top=200px,left=300,height=200px,width=300px' ).focus()";> Link_One </a>

    But if you want to do some other stuff inside the function before the actual opening of the window, like getting the left and top coordinates to center the popup to the screen and whatever, then use a function.

  • #8
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ...drives the scroll to the top of the document:

    <a href="#" onclick="window.open( 'something.html' ,'somethingtitle' , 'top=200px,left=300,height=200px,width=300px' )";> Link_One </a>


    anyway...

    <a href="javascript:window.open('something.html','somethingtitle','top=200px,left=300,height=200px,widt h=300px');void(0);"> Link_One </a>


    -james
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #9
    Regular Coder
    Join Date
    Dec 2003
    Location
    America
    Posts
    544
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Glen:

    Using functions is nice but not in the case of that launch_Pad example. No offense meant, but it looks like overkill to use a function.
    GOOD point. Don't know why simple things slip through my mind. But yea, your right.
    LovesWar

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Quote Originally Posted by jamescover
    ...drives the scroll to the top of the document:

    <a href="#" onclick="window.open( 'something.html' ,'somethingtitle' , 'top=200px,left=300,height=200px,width=300px' )";> Link_One </a>


    anyway...

    <a href="javascript:window.open('something.html','somethingtitle','top=200px,left=300,height=200px,widt h=300px');void(0);"> Link_One </a>


    -james
    <a href="something.html" target="somethingtitle" onclick="window.open( this.href, this.target , 'top=200px,left=300,height=200px,width=300px' ).focus();return false;"> Link_One </a>

  • #11
    Regular Coder
    Join Date
    Dec 2003
    Location
    America
    Posts
    544
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <a href="something.html" target="somethingtitle" onclick="window.open( this.href, this.target , 'top=200px,left=300,height=200px,width=300px' ).focus();return false;"> Link_One </a>
    So what does the return false here mean?
    LovesWar

  • #12
    Regular Coder
    Join Date
    Jul 2004
    Location
    engoku no anime
    Posts
    354
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I use it to ensure that the original page doesn't go all of the way back to the top of the document when the window opens (useful for super long pages). I don't know the logic behind it, but that is my purpose for including it.

  • #13
    New Coder
    Join Date
    Jun 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    reply to Roy Sinclair

    you're right, i am trying to get my head around javascript but can't seem to, reading paul wilson's beginning javascript & tom negrino javascript for the WWW 3rd edition.

    what confuses me is i have used this script as iis to call up two seperate windows, (the 2002 & 2003 button window/page) with no problems. but when i simply duplicated the same code i was using on the main (page 2) button page/window & changed the url & name to find the new page "2004", the script started finding the first "2002" & third "2004" page & couldn't call the 2003 page any more, even the 2003 button called up the 2004 events button window/page. confusing. anyway, i am going to print out the code, take your suggestions & see if i can fix it.
    thank you for your time.
    james
    Last edited by BossJames; 07-19-2004 at 12:45 AM.

  • #14
    New Coder
    Join Date
    Jun 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macintosh #2 reply to Roy Sinclair

    if i understand you correctly, i do not need to have this code on my homepage at all. correct?

    function openWindow(file,name) {
    if (screen) {
    var topPos = screen.height /2 -240;
    var leftPos = screen.width /2 -200;
    }
    var newWin = window.open(file,name,'width=200,height=500,left='+leftPo s+',top='+topPos+''); newWin.focus();

  • #15
    New Coder
    Join Date
    Jun 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macintosh reply to SpiritualStorms

    i only understand a limited amount. thanks for the explination.
    james


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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