window.open works in Firefox but not IE6/7

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DannyMc
    New Member
    • Aug 2007
    • 20

    window.open works in Firefox but not IE6/7

    Hi, i have tried this code in FireFox and it works great. However , it seems to fail in IE6/7. I have no idea and looking for help here. Please advice. Thank you.
    Code:
    <a
    ONCLICK="window.open('http://www.google.com,'height=180','width=250','location=no','menubar=no','resizable=no','scrollbars=yes','status=no','toolbar=no')" href="javascript:void(0)">
    Whois Agent local</a>
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    This code is programmed bad. Why do you need an "onclick"-event if your "href" is already reacting to the click? You disabled the clicking by using href="javascrip t:void(0)". So no wonder the browser gets confused and reacts differently on this error.
    Just use
    Code:
    <a href="javascript:window.open(...)>Whois Agent local</a>
    and it should work in all browsers.

    If it still does not work, then check your configuration (for example if you have disabled javascript in your brower)

    Originally posted by DannyMc
    Hi, i have tried this code in FireFox and it works great. However , it seems to fail in IE6/7. I have no idea and looking for help here. Please advice. Thank you.
    Code:
    <a
    ONCLICK="window.open('http://www.google.com,'height=180','width=250','location=no','menubar=no','resizable=no','scrollbars=yes','status=no','toolbar=no')" href="javascript:void(0)">
    Whois Agent local</a>

    Comment

    • DannyMc
      New Member
      • Aug 2007
      • 20

      #3
      Thank you Chaarmann, Your method seems to be more effective way to the javascript. However, i am still facing the same problem even using your suggested way.

      here is my function in php:
      Code:
      function open_me1(){
      window.open('http://www.google.com','height=300','width=250','location=no','menubar=no','resizable=no','scrollbars=yes','status=no','toolbar=no');
      Javascript:
      Code:
      <a href="javascript:open_me1();">Click To google</a><br />
      I manage to call the function in FireFox with no error message recorded in Error Console. On the other hand, IE6/7 the error message is invalid argument. This is weird.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        window.open() only has 3 or 4 parameters. The first is the URL. The second is the name of the window. The third specifies the properties. You've split these up into their own arguments - they should be grouped together as one. See, for example, this link.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by chaarmann
          This code is programmed bad. Why do you need an "onclick"-event if your "href" is already reacting to the click? You disabled the clicking by using href="javascrip t:void(0)".
          You should always use the href of a link in case JavaScript is disabled. It should really point to a real URL (in this case google.com). In the onclick, you can prevent the browser following the href link using return false. If you program like this, it will work whether JavaScript is enabled or not.

          Comment

          • chaarmann
            Recognized Expert Contributor
            • Nov 2007
            • 785

            #6
            Originally posted by acoder
            You should always use the href of a link in case JavaScript is disabled. It should really point to a real URL (in this case google.com). In the onclick, you can prevent the browser following the href link using return false. If you program like this, it will work whether JavaScript is enabled or not.
            Cool, I learned something new today. Especially that you can disable the href by returning "false" in your onClick. But that also means that the onClick is executed first. Is this the case in all common browsers?

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Originally posted by chaarmann
              Cool, I learned something new today. Especially that you can disable the href by returning "false" in your onClick. But that also means that the onClick is executed first. Is this the case in all common browsers?
              Yes, if JavaScript is enabled. If it's disabled, the href link will be followed. See these usability issues/tips for more information.

              Comment

              Working...