Pass Parameters to Java Script?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Al Franz

    Pass Parameters to Java Script?

    Anyone understand how to pass parameters to a JavaScript. If anyone finds
    this easy to do maybe they could take a look at my short script on this page
    and show me how it needs to be changed.



    Thanks for any help.


  • Laurent Bugnion, GalaSoft

    #2
    Re: Pass Parameters to Java Script?

    Hi,

    Al Franz wrote:[color=blue]
    > Anyone understand how to pass parameters to a JavaScript. If anyone finds
    > this easy to do maybe they could take a look at my short script on this page
    > and show me how it needs to be changed.
    >
    > http://franz.org/java.htm
    >
    > Thanks for any help.[/color]

    The page doesn't work.

    I assume that you are talking about passing parameters from Java to
    JavaScript, since you post in comp.lang.java. javascript. If it is so,
    then you should check


    HTH,

    Laurent
    --
    Laurent Bugnion, GalaSoft
    Webdesign, Java, JavaScript: http://www.galasoft-LB.ch
    Private/Malaysia: http://mypage.bluewin.ch/lbugnion
    Support children in Calcutta: http://www.calcutta-espoir.ch

    Comment

    • Al Franz

      #3
      Re: Pass Parameters to Java Script?

      Actually what I want to do is pass parameters from my HTML code to the
      JavaScript. Not sure why the web page does not work for you, are others
      having problems? Maybe it had a hiccup?


      Comment

      • Mark

        #4
        Re: Pass Parameters to Java Script?


        "Al Franz" <albert@netmati on.com> wrote in message
        news:IzVZa.1237 01$YN5.85449@sc crnsc01...[color=blue]
        > Anyone understand how to pass parameters to a JavaScript. If anyone finds
        > this easy to do maybe they could take a look at my short script on this[/color]
        page[color=blue]
        > and show me how it needs to be changed.
        >
        > http://franz.org/java.htm
        >
        > Thanks for any help.
        >
        >[/color]

        Add additional parameters to the function call:
        <A HREF="javascrip t:launch('photo/2003047.jpg', 500, 300)">

        Then, in your function:
        function launch(url, wdth, hght) {
        remote =
        open(url,'','re sizable=yes,scr ollbars=yes,too lbar=no,locatio n=no,directorie s
        =no,status=no,m enubar=no,copyh istory=no,width =wdth,height=hg ht');
        }

        No difference between passing 1 (url) and 3 (url, height, width)-- pass more
        if you like.

        HTH


        Comment

        • Laurent Bugnion, GalaSoft

          #5
          Re: Pass Parameters to Java Script?

          Hi,

          Mark wrote:[color=blue]
          > "Al Franz" <albert@netmati on.com> wrote in message
          > news:IzVZa.1237 01$YN5.85449@sc crnsc01...
          >[color=green]
          >>Anyone understand how to pass parameters to a JavaScript. If anyone finds
          >>this easy to do maybe they could take a look at my short script on this[/color]
          >
          > page
          >[color=green]
          >>and show me how it needs to be changed.
          >>
          >>http://franz.org/java.htm
          >>
          >>Thanks for any help.
          >>
          >>[/color]
          >
          >
          > Add additional parameters to the function call:
          > <A HREF="javascrip t:launch('photo/2003047.jpg', 500, 300)">
          >
          > Then, in your function:
          > function launch(url, wdth, hght) {
          > remote =
          > open(url,'','re sizable=yes,scr ollbars=yes,too lbar=no,locatio n=no,directorie s
          > =no,status=no,m enubar=no,copyh istory=no,width =wdth,height=hg ht');
          > }
          >
          > No difference between passing 1 (url) and 3 (url, height, width)-- pass more
          > if you like.
          >
          > HTH[/color]

          For various reasons (see the FAQ of comp.lang.javas cript), you should
          never use the pseudo-protocol "javascript :".

          The best way is to use the ONCLICK event handler, and to use the SRC
          attribute to specify an action which will be executed only if JavaScript
          is not enabled (if you return false in the ONCLICK event handler).

          Example:

          <A HREF="nojs.html "
          ONCLICK="myMeth od();return false;">
          Text</A>

          nojs.html being a page handling the case where the user doesn't have
          JavaScript.

          Laurent
          --
          Laurent Bugnion, GalaSoft
          Webdesign, Java, JavaScript: http://www.galasoft-LB.ch
          Private/Malaysia: http://mypage.bluewin.ch/lbugnion
          Support children in Calcutta: http://www.calcutta-espoir.ch

          Comment

          • Laurent Bugnion, GalaSoft

            #6
            Re: Pass Parameters to Java Script?

            Actually, the script you propose doesn't work. See correction under.

            Mark wrote:[color=blue]
            > "Al Franz" <albert@netmati on.com> wrote in message
            > news:IzVZa.1237 01$YN5.85449@sc crnsc01...
            >[color=green]
            >>Anyone understand how to pass parameters to a JavaScript. If anyone finds
            >>this easy to do maybe they could take a look at my short script on this[/color]
            >
            > page
            >[color=green]
            >>and show me how it needs to be changed.
            >>
            >>http://franz.org/java.htm
            >>
            >>Thanks for any help.
            >>
            >>[/color]
            >
            >
            > Add additional parameters to the function call:
            > <A HREF="javascrip t:launch('photo/2003047.jpg', 500, 300)">
            >
            > Then, in your function:[/color]

            Should be:

            function launch( url, wdth, hght )
            {
            remote = open( url, "WindowName ",
            'resizable,scro llbars,width='
            + wdth + ',height=' + hght );
            }

            What I did is

            1) Give a name to the window. A window should always have a unique name,
            to avoid nasty side effects.

            2) Remove all the parameters which are set to "no" in the open method.
            Parameters are set to "no" per default. It's not wrong to mention them,
            but it's not useful.

            3) wdth and hght are parameters, thus the string should be constructed
            using the concatenation operator '+'.

            HTH,

            Laurent
            --
            Laurent Bugnion, GalaSoft
            Webdesign, Java, JavaScript: http://www.galasoft-LB.ch
            Private/Malaysia: http://mypage.bluewin.ch/lbugnion
            Support children in Calcutta: http://www.calcutta-espoir.ch

            Comment

            • Al Franz

              #7
              Re: Pass Parameters to Java Script?

              Laurent,

              Thank you very much, it is looking better but have a few follow up
              questions. I implemented what you said at, even though I kept 2 "no"
              parameters in there in case I change those....



              1. Can I put the WindowName as a parameter in the HTML, since currently I
              have to close a popup before opening a new one since the old parameters will
              stick. Should it be in quotes in my HTML, and setup the same as wdth and
              hght ?

              2. Any way to set a background color for the frame in the window that pops
              up?

              3. Finnaly the wdth and hght I used as a parameter is the actual photo width
              + 20 pixels and the actual photo height + 30 pixels. Would it be possible
              to hard code the 20 and 30 in the script so I could put the actual photo
              dimensions in the HTML code parameters.

              Thanks again, any help with me finishing up these mods would be great.

              --Al


              Comment

              • Mark

                #8
                Re: Pass Parameters to Java Script?


                [Original message clipped for brevity][color=blue]
                >
                > http://franz.org/java.htm
                >
                > 1. Can I put the WindowName as a parameter in the HTML, since currently I
                > have to close a popup before opening a new one since the old parameters[/color]
                will[color=blue]
                > stick. Should it be in quotes in my HTML, and setup the same as wdth and
                > hght ?[/color]

                Yes, I mentioned you may pass the function any reasonable number of
                arguements. Window name would be an arguement. Use it as you would any
                other-- string arguements are passed in quotes, but do not quote the dummy
                variable.
                [color=blue]
                >
                > 2. Any way to set a background color for the frame in the window that pops
                > up?[/color]

                Hmmm... Not sure on this one. I suspect not-- as you are not actually
                opening a document, but rather only an image. if your 'url' was an HTML
                document, you could set the background color as in any other document.
                Perhaps someone else will know better, or perhaps changing the 'url'
                variable to an actual page containing the image is the only way.
                [color=blue]
                >
                > 3. Finnaly the wdth and hght I used as a parameter is the actual photo[/color]
                width[color=blue]
                > + 20 pixels and the actual photo height + 30 pixels. Would it be possible
                > to hard code the 20 and 30 in the script so I could put the actual photo
                > dimensions in the HTML code parameters.
                >[/color]

                Yes. In the opener function add +20 and +30 to the variables describing
                height and width.

                [color=blue]
                > Thanks again, any help with me finishing up these mods would be great.
                >
                > --Al[/color]

                Also, my thanks to Laurent Bugnion for 'fleshing out' my answers-- and my
                understanding.

                Mark[color=blue]
                >
                >[/color]


                Comment

                • Al Franz

                  #9
                  Re: Pass Parameters to Java Script?

                  Tried adding that 20 and 30 every which way I could, but doesn't seem to
                  work. What is wrong with this format???


                  <SCRIPT language=javasc ript>
                  function launch4( url, wdth, hght)
                  {
                  remote = open( url, "WindowName ",
                  'resizeable=no, scrollbars=no,w idth='
                  + wdth+20 + ',height='+ hght+30 );
                  }
                  </SCRIPT>


                  "Mark" <none@given.com > wrote in message
                  news:y5f_a.9005 5$Vt6.28698@rwc rnsc52.ops.asp. att.net...[color=blue]
                  >
                  > [Original message clipped for brevity][color=green]
                  > >
                  > > http://franz.org/java.htm
                  > >
                  > > 1. Can I put the WindowName as a parameter in the HTML, since currently[/color][/color]
                  I[color=blue][color=green]
                  > > have to close a popup before opening a new one since the old parameters[/color]
                  > will[color=green]
                  > > stick. Should it be in quotes in my HTML, and setup the same as wdth[/color][/color]
                  and[color=blue][color=green]
                  > > hght ?[/color]
                  >
                  > Yes, I mentioned you may pass the function any reasonable number of
                  > arguements. Window name would be an arguement. Use it as you would any
                  > other-- string arguements are passed in quotes, but do not quote the dummy
                  > variable.
                  >[color=green]
                  > >
                  > > 2. Any way to set a background color for the frame in the window that[/color][/color]
                  pops[color=blue][color=green]
                  > > up?[/color]
                  >
                  > Hmmm... Not sure on this one. I suspect not-- as you are not actually
                  > opening a document, but rather only an image. if your 'url' was an HTML
                  > document, you could set the background color as in any other document.
                  > Perhaps someone else will know better, or perhaps changing the 'url'
                  > variable to an actual page containing the image is the only way.
                  >[color=green]
                  > >
                  > > 3. Finnaly the wdth and hght I used as a parameter is the actual photo[/color]
                  > width[color=green]
                  > > + 20 pixels and the actual photo height + 30 pixels. Would it be[/color][/color]
                  possible[color=blue][color=green]
                  > > to hard code the 20 and 30 in the script so I could put the actual photo
                  > > dimensions in the HTML code parameters.
                  > >[/color]
                  >
                  > Yes. In the opener function add +20 and +30 to the variables describing
                  > height and width.
                  >
                  >[color=green]
                  > > Thanks again, any help with me finishing up these mods would be great.
                  > >
                  > > --Al[/color]
                  >
                  > Also, my thanks to Laurent Bugnion for 'fleshing out' my answers-- and my
                  > understanding.
                  >
                  > Mark[color=green]
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  • Harlan Messinger

                    #10
                    Re: Pass Parameters to Java Script?


                    "Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_S PAM.ch> wrote in
                    message news:3F391B7F.3 030106@bluewin_ NO_SPAM.ch...[color=blue]
                    >
                    > For various reasons (see the FAQ of comp.lang.javas cript), you should
                    > never use the pseudo-protocol "javascript :".[/color]

                    Is anyone imagined to be able to find anything in this "FAQ"? At
                    www.faqs.org is a "meta-FAQ" that points to a supposed "FAQ" at
                    http://developer.irt.org/script/script.htm -- but go ahead and try to figure
                    out where any information is located there about the pseudo-protocol
                    "javascript :".

                    Anyway, I've never come across this admonition, and I don't know why not to
                    use "javascript :". Several years of experience with it has turned up no
                    direct evidence of a problem. Can you fill us in?

                    Comment

                    • Jim Dabell

                      #11
                      Re: Pass Parameters to Java Script?

                      Harlan Messinger wrote:
                      [color=blue]
                      >
                      > "Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_S PAM.ch> wrote in
                      > message news:3F391B7F.3 030106@bluewin_ NO_SPAM.ch...[color=green]
                      >>
                      >> For various reasons (see the FAQ of comp.lang.javas cript), you should
                      >> never use the pseudo-protocol "javascript :".[/color]
                      >
                      > Is anyone imagined to be able to find anything in this "FAQ"? At
                      > www.faqs.org is a "meta-FAQ" that points to a supposed "FAQ" at
                      > http://developer.irt.org/script/script.htm -- but go ahead and try to
                      > figure out where any information is located there about the
                      > pseudo-protocol "javascript :".[/color]

                      Google: type in comp.lang.java. javascript faq. The very first hit leads you
                      to the comp.lang.javas cript FAQ (scroll down to "Javascript newsgroups").
                      See 4.24: I have <a href="javascrip t:somefunction( )"> what ... ?

                      [color=blue]
                      > Anyway, I've never come across this admonition, and I don't know why not
                      > to use "javascript :". Several years of experience with it has turned up no
                      > direct evidence of a problem. Can you fill us in?[/color]

                      The biggest problem with it is that it is useless in situations where
                      Javascript is not available. Even when it is available, it's problematic.

                      I find it extremely annoying to middle-click on a link to open it in a new
                      window, switch back to the original window immediately, carry on reading
                      that page, close it, and discover that the "link" wasn't a proper link at
                      all, and you are left with a blank page. This typically happens to me when
                      the author decided that the link _absolutely must_ open in a new window,
                      which just adds to the annoyance - it's like I am being punished for
                      operating my browser correctly.


                      --
                      Jim Dabell

                      Comment

                      • Harlan Messinger

                        #12
                        Re: Pass Parameters to Java Script?


                        "Jim Dabell" <jim-usenet@jimdabel l.com> wrote in message
                        news:Z4CdnfQ7Kr U52aeiXTWQkQ@gi ganews.com...[color=blue]
                        > Harlan Messinger wrote:
                        >[color=green]
                        > >
                        > > "Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_S PAM.ch> wrote in
                        > > message news:3F391B7F.3 030106@bluewin_ NO_SPAM.ch...[color=darkred]
                        > >>
                        > >> For various reasons (see the FAQ of comp.lang.javas cript), you should
                        > >> never use the pseudo-protocol "javascript :".[/color]
                        > >
                        > > Is anyone imagined to be able to find anything in this "FAQ"? At
                        > > www.faqs.org is a "meta-FAQ" that points to a supposed "FAQ" at
                        > > http://developer.irt.org/script/script.htm -- but go ahead and try to
                        > > figure out where any information is located there about the
                        > > pseudo-protocol "javascript :".[/color]
                        >
                        > Google: type in comp.lang.java. javascript faq. The very first hit leads[/color]
                        you[color=blue]
                        > to the comp.lang.javas cript FAQ (scroll down to "Javascript newsgroups").
                        > See 4.24: I have <a href="javascrip t:somefunction( )"> what ... ?
                        >
                        >[color=green]
                        > > Anyway, I've never come across this admonition, and I don't know why not
                        > > to use "javascript :". Several years of experience with it has turned up[/color][/color]
                        no[color=blue][color=green]
                        > > direct evidence of a problem. Can you fill us in?[/color]
                        >
                        > The biggest problem with it is that it is useless in situations where
                        > Javascript is not available.[/color]

                        <snicker> In those cases the ONCLICK is going to be *real* helpful.
                        [color=blue]
                        > Even when it is available, it's problematic.
                        >
                        > I find it extremely annoying to middle-click on a link to open it in a new
                        > window, switch back to the original window immediately, carry on reading
                        > that page, close it, and discover that the "link" wasn't a proper link at
                        > all, and you are left with a blank page. This typically happens to me[/color]
                        when[color=blue]
                        > the author decided that the link _absolutely must_ open in a new window,
                        > which just adds to the annoyance - it's like I am being punished for
                        > operating my browser correctly.[/color]

                        This has nothing to do with using "javascript :" in an HREF. You're
                        complaining about a particular *action* that some site editors associate
                        with a link.

                        Comment

                        • Jim Dabell

                          #13
                          Re: Pass Parameters to Java Script?

                          Harlan Messinger wrote:
                          [color=blue]
                          > "Jim Dabell" <jim-usenet@jimdabel l.com> wrote in message
                          > news:Z4CdnfQ7Kr U52aeiXTWQkQ@gi ganews.com...[/color]
                          [snip][color=blue][color=green]
                          >> The biggest problem with it is that it is useless in situations where
                          >> Javascript is not available.[/color]
                          >
                          > <snicker> In those cases the ONCLICK is going to be *real* helpful.[/color]

                          No, but the href attribute will be, won't it? Or were you planning on
                          having a link without an href attribute?

                          [color=blue][color=green]
                          >> I find it extremely annoying to middle-click on a link to open it in a
                          >> new window, switch back to the original window immediately, carry on
                          >> reading that page, close it, and discover that the "link" wasn't a proper
                          >> link at all, and you are left with a blank page. This typically happens
                          >> to me when the author decided that the link _absolutely must_ open in a
                          >> new window, which just adds to the annoyance - it's like I am being
                          >> punished for operating my browser correctly.[/color]
                          >
                          > This has nothing to do with using "javascript :" in an HREF.[/color]

                          It's the root cause of the problem. I don't see how you can argue
                          otherwise. If a normal link was used, it wouldn't break in this situation.

                          [color=blue]
                          > You're complaining about a particular *action* that some site editors
                          > associate with a link.[/color]

                          No, the href attribute is the defining quality of a link. There's only one
                          defined instance where the context of the link matters in HTML, and that is
                          with relative URLs. The javascript: style links can be context-free, which
                          is the cause of the problem - openFancyWindow (); is meaningless in a new
                          window.

                          While an "open in a new window" link that is implemented using events is
                          annoying, it's nowhere near as annoying as the fundamentally broken
                          javascript: problem.

                          --
                          Jim Dabell

                          Comment

                          • Richard Cornford

                            #14
                            Re: Pass Parameters to Java Script?

                            "Harlan Messinger" <h.messinger@co mcast.net> wrote in message
                            news:bhdtd7$111 769$1@ID-114100.news.uni-berlin.de...[color=blue]
                            >"Jim Dabell" <jim-usenet@jimdabel l.com> wrote in message
                            >news:Z4CdnfQ7K rU52aeiXTWQkQ@g iganews.com...[color=green]
                            >> Harlan Messinger wrote:[/color][/color]
                            <snip>[color=blue][color=green][color=darkred]
                            >>>Anyway, I've never come across this admonition, and I don't
                            >>>know why not to use "javascript :". Several years of experience
                            >>>with it has turned up no direct evidence of a problem. Can you
                            >>>fill us in?[/color]
                            >>
                            >>The biggest problem with it is that it is useless in situations
                            >>where Javascript is not available.[/color]
                            >
                            ><snicker> In those cases the ONCLICK is going to be *real* helpful.[/color]
                            <snip>

                            The point is not that the onclick event is usable if JavaScript is
                            disabled, it is that there is a one to one relationship between
                            JavaScript being available and enabled and the execution of onclick
                            code. While a javascript: pseudo protocol href is still an href even if
                            JavaScript is not available; If JavaScript is unavailable the result of
                            clicking on the link is unpredictable but will always be unhelpful.
                            Conversely, an onclick handler can cancel the navigation specified by a
                            real URL in the href, and when JavaScript is not available (or the
                            browser lacks the features required by the script) the URL in the href
                            provides a natural and reliable path of clean degradation.

                            But the consequences of the use of the javascript: pseudo-protocol when
                            JavaScript is unavailable are not to only reason for not using it. Some
                            browsers (and this depends a lot on browser type, version and OS) treat
                            the user clicking on a link as navigation (if not cancelled by an
                            onclick handler) and navigation is taken to mean that the current page
                            is finished with. They start to shut down resource hungry activity on
                            the current page (waiting for it to be replaced). The most commonly
                            observed manifestation of this (because it happens on Windows OS with
                            some IE versions) is that once a javascript: pseudo-protocol link is
                            clicked animated GIF images stop being animated. There are other
                            manifestations and Mac and Linux browsers seem generally more
                            susceptible than Window browsers.

                            Exactly which (if any) resources will vanish when a javascript:
                            pseudo-protocol link is clicked (and on which browser versions and OSs)
                            is not well documented but it is known with 100% certainty that the
                            whole problem can be avoided on all current browsers by exclusively
                            using onclick handlers when the desire is to execute JavaScript as a
                            consequence of clicking on a link.

                            Section 2.24 of the comp.lang.javas cript FAQ may be mostly motivated by
                            a desire to provide clean degradation in a JavaScript incapable
                            environment but that is not the only reason that it includes such a
                            blanket injunction against the use of the javascript: pseudo-protocol in
                            href attributes.

                            Richard.


                            Comment

                            Working...