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
    Mar 2004
    Posts
    91
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem formatting call to window.open()

    Hello

    I am trying to open a new browser page using window.open
    If I do the following, everything works out fine:
    Code:
    window.open('myPage.php?param1=value1&param2=value2','_blank','status=no,scrollbars=yes,location=no,height=200,width=200');
    The problem is that the URL parameters, width and height of the page are parameters that I receive as variables.
    That lead me to the following attempt:
    Code:
    function showFullSizePhoto(URLParams, width, height) {
      var url = "myPage.php?" + URLParams;	
      parameters = "status=no,scrollbars=yes,location=no,height=" + height + ", width=" + width;
      var target = "'" + url + "','_blank','" + parameters + "'";
      window.open(target);
    }
    Unfortunately, this doesn't work.
    It seems like there is a syntax problem of using the single quotes.
    Can anyone show me what the correct syntax should be?

    thanks

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

    Why dont you just do something like this:

    it seems to me like all you would have to do is do something like this:

    Code:
    function popWindow(fileAddy,windName,features) {
    
    var wolfy;
    
    wolfy=window.open(fileAddy,windName,features);
    
    wolfy.focus();
    }
    Once you have the above, you can then do something like this:

    Code:
    <input type="button" value="pop" onClick="popWindow('Moving_Images.html','Moving_Object','width=440px, height=150px,top=300px,left=300px');">
    
    <input type="button" value="pop" onClick="popWindow('Buttons_tuts.html','Moving_Object','width=440px, height=150px,top=300px,left=300px');">
    Since your function would have parameters, you can basically pass those very same parameters as values to the open() method.

    Generally, there's 3 main paramter areas to the window.open() method, those are the file, or url path of the document, the name of the window, and the features the window will have. This being the case, you must seperate all parameters with a comma, and all the values must be enclosed in quotes. If you wish to actually use a quote on your variable, you will need to escape with the back-slash. Example, var sentence="And he said, and i quote,\" Moo!\" ";

    Now your variable will actually have the quotation marks. The backlash is a way of escaping the general meaning of a symbol that already stands for something.

    The parameters are no different. Parameters are actually another way of declaring a variable, hence when you call a function, and actually supply the functions with values, you must use quotes.

    For this reason, if you have the 3rd parameter, you could just do something like this, "width=440px, height=150px,top=300px,left=300px". The whole thing will be passed to a parameter by the name of features, if thats the name you want to use. Translated, when you call a function, and pass it values to one of its parameters, you are basically do something like this,

    Code:
    var features  = "width=440px, height=150px,top=300px,left=300px";
    The above is no different than,

    Code:
    function popWindow(fileAddy,windName,features) {
    
    var wolfy;
    
    wolfy=window.open(fileAddy,windName,features);
    
    wolfy.focus();
    }
    With the above, you are now ready to pass the function values. And you do this, by doing this,

    Code:
    <input type="button" value="pop" onClick="popWindow('Moving_Images.html','Moving_Object','width=440px, height=150px,top=300px,left=300px');">
    
    <input type="button" value="pop" onClick="popWindow('Buttons_tuts.html','Moving_Object','width=440px, height=150px,top=300px,left=300px');">
    I hope i have helped.
    LovesWar

  • #3
    New Coder
    Join Date
    Mar 2004
    Posts
    91
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks a lot
    you really helped me

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

    I also forgot to tell you.

    I noticed that in your script you had something like, location=no. If you do not want a certain feature, then do not list it. The default is always a no. This being the case, you should should only list a feature if you want a yes. Thus, saying something like, location=yes, is alot more effective than saying, location=no, since its already assumed that you do not want it.
    LovesWar

  • #5
    New Coder
    Join Date
    Mar 2004
    Posts
    91
    Thanks
    0
    Thanked 0 Times in 0 Posts
    actually, the default for the location attribute is yes.
    location = { yes | no | 1 | 0 } Specifies whether to display the input field for entering URLs directly into the browser. The default is yes.

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

    You base this on what?

    Did you test it yourself? Or are you assuming from the syntax that it is?
    LovesWar

  • #7
    New Coder
    Join Date
    Mar 2004
    Posts
    91
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I just tried it.
    You are right. Microsoft's documentation is wrong!
    Still, I prefer to leave it like that so that if someone else reads the code and then looks at the documentation, he won't get confused.

    thanks

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

    No problem.

    I generally get my info from books. The way i look at it, if they can produce a book, chances are, they know a thing or two, which isnt always true, i know, but it does give you a rule of thumbs to go by.

    Secondly, i use pop ups a lot, i think they are great for like the pulling of additional info through a small window. At any rate, if you were right, then many of the features that i do not list should have sprang on me whenever i use a pop-up. But because they dont, i take that pretty much as a sign that the default values of any unlisted feature is a no, hence if i want it, i have to not only list it, but i have to give it a positive value.
    LovesWar


  •  

    Posting Permissions

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