window.open not working from inside user defined function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mountain Man

    window.open not working from inside user defined function

    Hi,

    I'm trying to use window.open from inside a user defined function, and
    it's not working. A code example is shown below. Thanks for any help
    you can give.

    Mountain Man
    ============

    <script>

    function openFootnote(co ntentURL) {
    window.open('co ntentURL','foot notes','height= 180,width=160') ;
    }

    </script>

    I've tried calling on the function 2 different ways, as shown below.
    Nothing happens either way.

    <a href="javascrip t:(void)" onClick="openFo otnote(fn1.html );">...</a>

    <a href="javascrip t:(void)" onClick="return
    openFootnote(fn 1.html);">...</a>
  • Erwin Moller

    #2
    Re: window.open not working from inside user defined function

    Mountain Man wrote:
    [color=blue]
    > Hi,
    >
    > I'm trying to use window.open from inside a user defined function, and
    > it's not working. A code example is shown below. Thanks for any help
    > you can give.
    >
    > Mountain Man
    > ============
    >
    > <script>
    >
    > function openFootnote(co ntentURL) {
    > window.open('co ntentURL','foot notes','height= 180,width=160') ;
    > }
    >
    > </script>
    >
    > I've tried calling on the function 2 different ways, as shown below.
    > Nothing happens either way.
    >
    > <a href="javascrip t:(void)" onClick="openFo otnote(fn1.html );">...</a>
    >
    > <a href="javascrip t:(void)" onClick="return
    > openFootnote(fn 1.html);">...</a>[/color]

    Send the URL as a string, that may help.
    openFootnote('f n1.html');

    Regards,
    Erwin Moller

    Comment

    • Michael Winter

      #3
      Re: window.open not working from inside user defined function

      On 26 Feb 2004 03:41:33 -0800, Mountain Man <eightypoundpac k@yahoo.com>
      wrote:
      [color=blue]
      > I'm trying to use window.open from inside a user defined function, and
      > it's not working. A code example is shown below. Thanks for any help
      > you can give.
      >
      > <script>[/color]

      The type attribute is required. That should read:

      <script type="text/javascript">
      [color=blue]
      > function openFootnote(co ntentURL) {
      > window.open('co ntentURL','foot notes','height= 180,width=160') ;[/color]

      That line passes the string 'contentURL' as the URL, not the value held by
      the variable, contentURL.

      window.open(con tentURL,'footno tes','height=18 0,width=160');
      [color=blue]
      > }
      >
      > </script>
      >
      > I've tried calling on the function 2 different ways, as shown below.
      > Nothing happens either way.
      >
      > <a href="javascrip t:(void)" onClick="openFo otnote(fn1.html );">...</a>[/color]

      Read the FAQ, specifically:



      The statement:

      openFootnote(fn 1.html);

      does not do what you think it does. The browser will look for the variable
      fn1, then its property, html. What you are trying to do is pass a string
      literal to the function. Use:

      openFootnote('f n1.html');

      Also, you will want to cancel the navigation, so the intrinsic event
      should read:

      onclick="openFo otnote('fn1.htm l');return false;"
      [color=blue]
      > <a href="javascrip t:(void)" onClick="return
      > openFootnote(fn 1.html);">...</a>[/color]

      As openFootnote() doesn't return a value, there is no point in adding the
      return keyword.

      I seriously suggest you read about the language before trying to hack away
      with it. The FAQ for this group contains links and book suggestions. I
      would advise you to read some of the material.

      Mike


      comp.lang.javas cript FAQ:



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

      Comment

      Working...