SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Mar 2008
    Location
    Rock Hill, SC
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pass parameters to js

    What I want to do is create a popup that will be the "receiving container". It will display with these components:

    Header 1
    Header 2
    Text 1
    Text 2
    Image

    Additionally the top and left positions need to be changeable.

    If I were programming in Visual FoxPro (25 yrs experience) I would expect to build the content of each of these components into individual variables, and then pass them to a function:

    var newWindow = null;
    var head1 = "Hello"
    var head2 = "World"
    var text1 = "This is the first paragraph"
    var text2 = "This is the second paragraph"
    var myImage = "yadda.jpg"
    var myLeft = 200
    var myTop = 300

    ...and then call the popup thus:

    function popItUp(win,head1,head2,text1,text2,myImage,myLeft,myTop) {
    var windowFile = win + ".htm"
    newWindow = open(windowFile, win, head1 ... etc. "scrollbars,resizable,width=500,height=400");
    }

    So -- quite simply how do I do it? (Function popItUp was adapted from Java Script for Dummies, p. 147).
    _________________
    Dave

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    You would create a new documentFragment and append to that the elements you wish to be in the body of the new window. After you create the new window you wouls append to it the document fragment.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Mar 2008
    Location
    Rock Hill, SC
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Quote Originally Posted by pmw57 View Post
    You would create a new documentFragment and append to that the elements you wish to be in the body of the new window. After you create the new window you would append to it the document fragment.
    Ok. That makes sense. Thanks for helping.

    What I have done so far with the existing five (of 80) links on my website (Galleries, Portraits, five thumbs on left with names -- names are links) -- is create a separate popup htm file for each one. I have no current control over left and top, and have to tweak height and width in each one as it is presented.

    What I want to have is a single htm popup file to which I will pass the contents and the height, width, top and left components as parameters.

    So, how do I construct the documentFragment to do this?

    Once I understand the nuts and bolts of the parameter passing, I will have no problem cloning the concept through all 80 images.

  4. #4
    SitePoint Member Tybe-O's Avatar
    Join Date
    Mar 2008
    Location
    NL, Rotterdam
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The basis approach would be:

    1. Spawn a popup with the desired size and window params.
    2. Prepare the content you want to place in the popup.
    3. Write the content directly to the popup or by means of calling a javascript function present in the loaded popup page.


    Essential is dat you have window.open return a reference to the popup window.

    Code JavaScript:
    var myPopupWindow = window.open(url,name,features);
     
    // write directly
    myPopupWindow.document.write('jibbajabba');
     
    // or call some method
    myPopupWindow.placeContent(arg1,arg2);

    See: http://www.quirksmode.org/js/popup.html#writing

  5. #5
    SitePoint Member
    Join Date
    Mar 2008
    Location
    Rock Hill, SC
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I hope I haven't appeared rude in taking so long to reply, but your answer to my question had a lot of "meat" on its "bones". I followed your link to quirksmode, and from there to the cross-window page. Downloaded all the contents of both pages, and have been studying them with great interest.

    I confess I haven't had my "Aha" moment yet, but at least now I have some good information to work with. Once I have succeeded in hacking into a passed parameter in some sample code, I know I'll be good to go.

    In this:

    var newwindow = '';

    function popitup(url) {
    if (!newwindow.closed && newwindow.location) {
    newwindow.location.href = url;
    }
    else {
    newwindow=window.open(url,'name','height=200,width=150');
    if (!newwindow.opener) newwindow.opener = self;
    }
    if (window.focus) {newwindow.focus()}
    return false;
    }

    and specifically the "else {" section, how do I pass in, say, the height value as a value in a variable? In other words, how might I save this guy as an HTM file, and then call it with externally defined variables?

  6. #6
    SitePoint Member Tybe-O's Avatar
    Join Date
    Mar 2008
    Location
    NL, Rotterdam
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure what it is exactly that you're asking in the end of your post, but if it is about how to use with/height vars to control the popup-size:

    Code JavaScript:
    function spawnPopup(strPopupUrl,intPopupW,intPopupH)
    {
      var strPopupOptions = "width="+intPopupW+",height="+intPopupH;
      var objNewWindow = window.open(strPopupUrl,"",strPopupOptions);
     
      return objNewWindow;
    }

    Referring to my previous example:
    • If you create the popup contents on the fly you would create the html in a function existing in the page that spawns the popup (the master page). That function then writes to the created popup.
    • If you go for option two, the page loaded by the url-parameter has to hold a html document that has the placeContent() function. Then call that function from the master page.

  7. #7
    SitePoint Member
    Join Date
    Mar 2008
    Location
    Rock Hill, SC
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Ok, I'm getting the picture. Getting ready to pack it in today, but I'll give it a wallop in the morning.

    Part of my main problem here is that I'm not trying to become a Java Script programmer, merely tweak my website. Your help is tremendous!


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
  •