n00b ? href=javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dana Smith

    n00b ? href=javascript

    Can anybody explain why when I have a hyperlink on a page with the code
    similar to below, after the user clicks on the link, the desired window
    opens but the page with the hyperlink changes to a new page with simply the
    value "[object]" on it? I want the original page to remain unchanged....
    thanks for the insight to a javascript n00bie... :)

    <a href="javascrip t:window.open(' wireless.htm', 'pjtdetails',
    config='height= 400, width=400, toolbar=no, menubar=no, scrollbars=yes,
    resizable=yes, location=no')">
    asdfalkjsdflbka jsdf</a>


  • Harag

    #2
    Re: n00b ? href=javascript


    try this instead: (all on one line)

    <a href="#" onClick="window .open('wireless .htm',
    'pjtdetails','h eight=400, width=400, toolbar=no, menubar=no,
    scrollbars=yes, resizable=yes, location=no')"> click me</a>


    HTH

    Al.



    On Wed, 14 Jan 2004 16:15:49 -0500, "Dana Smith"
    <dana_smith@com cast.net> wrote:
    [color=blue]
    ><a href="javascrip t:window.open(' wireless.htm', 'pjtdetails',
    >config='height =400, width=400, toolbar=no, menubar=no, scrollbars=yes,
    >resizable=ye s, location=no')">[/color]

    Comment

    • Michael Winter

      #3
      Re: n00b ? href=javascript

      On Wed, 14 Jan 2004 16:15:49 -0500, Dana Smith <dana_smith@com cast.net>
      wrote:
      [color=blue]
      > Can anybody explain why when I have a hyperlink on a page with the code
      > similar to below, after the user clicks on the link, the desired window
      > opens but the page with the hyperlink changes to a new page with simply
      > the
      > value "[object]" on it? I want the original page to remain unchanged....
      > thanks for the insight to a javascript n00bie... :)[/color]

      This is one of the hazards of using javascript: URIs. The better method is
      using the onclick event handler:

      <A href="" onclick="window .open(...);retu rn false">text</A>

      Notice the statement, 'return false'? This is also required to stop the
      browser from following the link (href="" is the same as the current page).
      Unless there is a specific reason to use a link, you should use a button
      instead:

      <BUTTON type="button" onclick="window .open(...)">tex t</BUTTON>

      Notice that the return statement is not needed.

      The moral of this story is, NEVER use javascript: URIs.
      [color=blue]
      > <a href="javascrip t:window.open(' wireless.htm', 'pjtdetails',
      > config='height= 400, width=400, toolbar=no, menubar=no, scrollbars=yes,
      > resizable=yes, location=no')">
      > asdfalkjsdflbka jsdf</a>[/color]

      The 'features' string (height=400,... ) shouldn't contain any spaces. That
      is, it should be written:

      "height=400,wid th=400,scrollba rs,resizable"

      Also notice that I omitted the disabled features. Boolean (yes/no) options
      default to 'no' when left out.

      Mike

      --
      Michael Winter
      M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

      Comment

      • Michael Winter

        #4
        Re: n00b ? href=javascript

        On Wed, 14 Jan 2004 21:59:55 +0000, Harag
        <harag@REMOVETH ESECAPITALSsoft home.net> wrote:

        [Quoted material snipped]
        [color=blue]
        > try this instead: (all on one line)
        >
        > <a href="#" onClick="window .open('wireless .htm',
        > 'pjtdetails','h eight=400, width=400, toolbar=no, menubar=no,
        > scrollbars=yes, resizable=yes, location=no')"> click me</a>[/color]

        This still has a problem; you don't cancel the event. Once the new window
        is opened, the original page will still be changed. Granted, it goes back
        to the same page, but it shouldn't happen at all, in this case.
        Furthermore, there shouldn't be any spaces in the 'features' string. You
        should append the following to the handler code (including the semi-colon):

        ;return false

        Mike

        And please, don't top-post. Place your response below, or amongst, quoted
        material and make sure you trim it as necessary. See my response to the
        OP, and posts to long threads (by regular posters) for examples.

        --
        Michael Winter
        M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

        Comment

        • Evertjan.

          #5
          Re: n00b ? href=javascript

          Michael Winter wrote on 14 jan 2004 in comp.lang.javas cript:
          [color=blue]
          > <BUTTON type="button" onclick="window .open(...)">tex t</BUTTON>[/color]

          A button is default of type button

          --
          Evertjan.
          The Netherlands.
          (Please change the x'es to dots in my emailaddress)

          Comment

          • DU

            #6
            Re: n00b ? href=javascript

            Evertjan. wrote:
            [color=blue]
            > Michael Winter wrote on 14 jan 2004 in comp.lang.javas cript:
            >
            >[color=green]
            >> <BUTTON type="button" onclick="window .open(...)">tex t</BUTTON>[/color]
            >
            >
            > A button is default of type button
            >[/color]

            Quite on the contrary. A button is default of type submit.



            A description of HTML 4's BUTTON element for submit, reset, or push buttons.


            DU

            Comment

            • Michael Winter

              #7
              Re: n00b ? href=javascript

              On 14 Jan 2004 22:37:20 GMT, Evertjan. <exjxw.hannivoo rt@interxnl.net >
              wrote:
              [color=blue]
              > Michael Winter wrote on 14 jan 2004 in comp.lang.javas cript:
              >[color=green]
              >> <BUTTON type="button" onclick="window .open(...)">tex t</BUTTON>[/color]
              >
              > A button is default of type button[/color]

              Debatable.

              As far as Microsoft are concerned, the default is indeed a push button.
              According to the HTML 4.01 specification, the default is a submit button.

              I prefer to abide by the specification.

              Mike

              --
              Michael Winter
              M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

              Comment

              • DU

                #8
                Re: n00b ? href=javascript

                Michael Winter wrote:
                [color=blue]
                > On Wed, 14 Jan 2004 16:15:49 -0500, Dana Smith <dana_smith@com cast.net>
                > wrote:
                >[color=green]
                >> Can anybody explain why when I have a hyperlink on a page with the code
                >> similar to below, after the user clicks on the link, the desired window
                >> opens but the page with the hyperlink changes to a new page with
                >> simply the
                >> value "[object]" on it? I want the original page to remain unchanged....
                >> thanks for the insight to a javascript n00bie... :)[/color]
                >
                >
                > This is one of the hazards of using javascript: URIs. The better method
                > is using the onclick event handler:
                >
                > <A href="" onclick="window .open(...);retu rn false">text</A>
                >
                > Notice the statement, 'return false'? This is also required to stop the
                > browser from following the link (href="" is the same as the current
                > page). Unless there is a specific reason to use a link, you should use a
                > button instead:
                >
                > <BUTTON type="button" onclick="window .open(...)">tex t</BUTTON>
                >
                > Notice that the return statement is not needed.
                >
                > The moral of this story is, NEVER use javascript: URIs.
                >[color=green]
                >> <a href="javascrip t:window.open(' wireless.htm', 'pjtdetails',
                >> config='height= 400, width=400, toolbar=no, menubar=no, scrollbars=yes,
                >> resizable=yes, location=no')">
                >> asdfalkjsdflbka jsdf</a>[/color]
                >
                >
                > The 'features' string (height=400,... ) shouldn't contain any spaces.
                > That is, it should be written:
                >
                > "height=400,wid th=400,scrollba rs,resizable"
                >
                > Also notice that I omitted the disabled features. Boolean (yes/no)
                > options default to 'no' when left out.
                >
                > Mike
                >[/color]

                Your post is good and what you said is correct. But it still isn't a
                complete answer.

                1- If javascript support is disabled, the wireless.htm resource will not
                be loaded at all.
                E.g.
                <a href="wireless. htm" target="pjtdeta ils"
                onclick="window .open(this.href , this.target,
                'height=400,wid th=400,scrollba rs,resizable'); return
                false;">asdfalk jsdflbkajsdf</a>
                would avoid that.

                2- There are no accessibility support for the link to indicate that the
                link will normally open a new separate window. Adding a title attribute
                along with a new-window icon image would solve that. Doing so gives
                users more freedom (use right-click, choose contextmenu, modify
                settings,etc)
                E.g.
                <a href="wireless. htm" target="pjtdeta ils"
                onclick="window .open(this.href , this.target,
                'height=400,wid th=400,scrollba rs,resizable'); return false;"
                title="Clicking the link will create a new window
                (popup)">asdfal kjsdflbkajsdf</a>
                would avoid that.

                3- If the popup goes behind and if the user clicks again the link
                hoping/expecting the popup to be brought back up on top of the opener,
                nothing will happen. This happens often and this is known to be a very
                frequent usability problem for users. Here, you need to store a
                reference to the window object in a global variable and verify if the
                window was not closed.

                I have working examples on all this:

                This following page sums up all of the above into a single script
                function OpenRequestedPo pup


                Popup windows and Netscape 7: interactive demos
                (the demos will work in MSIE 6, Opera 7.x, etc.)


                DU

                Comment

                • Richard Cornford

                  #9
                  Re: n00b ? href=javascript

                  "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
                  news:opr1se00nc 5vklcq@news-text.blueyonder .co.uk...
                  <snip>[color=blue][color=green][color=darkred]
                  >>><BUTTON type="button" onclick="window .open(...)">tex t</BUTTON>[/color]
                  >>
                  >>A button is default of type button[/color]
                  >
                  >Debatable.
                  >
                  >As far as Microsoft are concerned, the default is indeed a push
                  >button. According to the HTML 4.01 specification, the default is
                  >a submit button.[/color]
                  [color=blue]
                  >I prefer to abide by the specification.[/color]

                  The effect of the discrepancy is that always including the type
                  attribute in button elements is a better idea than relying on the
                  defaults (because they will commonly not be uniform).

                  Richard.


                  Comment

                  • Michael Winter

                    #10
                    Re: n00b ? href=javascript

                    On Wed, 14 Jan 2004 18:04:21 -0500, DU <drunclear@hotR EMOVETHISmail.c om>
                    wrote:
                    [color=blue]
                    > Michael Winter wrote:[color=green]
                    >>
                    >> This is one of the hazards of using javascript: URIs. The better method
                    >> is using the onclick event handler:
                    >>
                    >> <A href="" onclick="window .open(...);retu rn false">text</A>[/color][/color]

                    <snipped the remainder of my original post>
                    [color=blue]
                    > Your post is good and what you said is correct. But it still isn't a
                    > complete answer.
                    >
                    > 1- If javascript support is disabled, the wireless.htm resource will not
                    > be loaded at all.[/color]

                    I realise this.
                    [color=blue]
                    > 2- There are no accessibility support for the link to indicate that the
                    > link will normally open a new separate window. Adding a title attribute
                    > along with a new-window icon image would solve that. Doing so gives
                    > users more freedom (use right-click, choose contextmenu, modify
                    > settings,etc)[/color]

                    Understand that, but didn't think about it at the time.
                    [color=blue]
                    > 3- If the popup goes behind and if the user clicks again the link
                    > hoping/expecting the popup to be brought back up on top of the opener,
                    > nothing will happen. This happens often and this is known to be a very
                    > frequent usability problem for users. Here, you need to store a
                    > reference to the window object in a global variable and verify if the
                    > window was not closed.[/color]

                    Hadn't thought of that at all - I wouldn't expect the user to do it.

                    The problem I find is one of information overload. In some cases
                    (particularly with novices), some of things I might think of will do
                    nothing but confuse the OP so I tend to be selective. However, I'll admit
                    that most of the time, some suggestions (like the latter two you raised)
                    simply don't occur to me.

                    Thank you.

                    Mike

                    --
                    Michael Winter
                    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

                    Comment

                    • Lee

                      #11
                      Re: n00b ? href=javascript

                      Michael Winter said:
                      [color=blue]
                      >The moral of this story is, NEVER use javascript: URIs.[/color]

                      Never use them in links, particularly simply for their side effects.
                      There are some cases where they are useful for their original purpose,
                      which is to replace the current page contents with the result of the
                      evaluated Javascript expression.

                      Of course, you have to know that the visitor has Javascript enabled.

                      Comment

                      • Harag

                        #12
                        Re: n00b ? href=javascript

                        On Wed, 14 Jan 2004 22:30:28 GMT, Michael Winter
                        <M.Winter@bluey onder.co.invali d> wrote:

                        [Quoted material snipped]
                        [color=blue]
                        >This still has a problem; you don't cancel the event. Once the new window
                        >is opened, the original page will still be changed. Granted, it goes back
                        >to the same page, but it shouldn't happen at all, in this case.
                        >Furthermore, there shouldn't be any spaces in the 'features' string. You
                        >should append the following to the handler code (including the semi-colon):
                        >
                        > ;return false[/color]

                        Ahh yes forgot about the return false; bit on the end. thanks for
                        pointing that out :)

                        The point about spaces in the "features" string is new to me so thanks
                        for that...
                        [color=blue]
                        >And please, don't top-post. Place your response below, or amongst, quoted
                        >material and make sure you trim it as necessary. See my response to the
                        >OP, and posts to long threads (by regular posters) for examples.[/color]

                        I just had this same sort of message in the MS JScript group. I'm new
                        to Jscript and just started subscribing to these two groups. FYI heres
                        what I put in the other group:

                        "Sorry about that. Some groups dont mind it and others do...I'm fairly
                        new to this group so I'll keep that in mind. Personally I dont mind it
                        as I use "Free agent" to read newsgroups and it saves me scrolling
                        when people have put quick replies at the top... as I can see the
                        previous reply just by clicking on the tree as its an offline reader."

                        From now on I'll convert over to not top posting. Then I'm safe where
                        ever I post.

                        Al.

                        Comment

                        Working...