window.open, Linux vs. Windows

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

    window.open, Linux vs. Windows

    I'm a complete Javascript n00b, using a snippet I found on the web.
    I'll probably be buying a Javascript book. What's the authoritative
    on-line resource for Javascript, like php.net is for PHP? I'm a
    relative PHP n00b.

    This code works fine on Opera & Mozilla under Linux, but fails for both
    Netscape & IE under Windows:

    <script language="JavaS cript">
    <!--
    function smallWindow(URL , X, Y, Title)
    {
    var win = window.open(URL , Title,
    'width='+X+',he ight='+Y+',resi zable=1,scrollb ars=1');
    }
    // -->
    </script>

    <form name="form1" method="post" action="">
    <html>
    <head>
    etc.
    a ton of PHP code echoing HTML, including:

    echo '<a href="javascrip t:onclick=small Window(\'unitco nverter.php\',
    \'250\', \'150\', \'Convert Units\');">';
    echo 'Unit Conversion Calculator';
    echo '</a>';


    I can open unitconverter.p hp stand-alone, as well as via a simple

    <a href="unitconve rter.php" target="new window">.

    It's only when I go through Javascript that it fails with nothing more
    than a friendly "Error in page" message from IE, while Netscape is mute.

    --
    Lynn Wallace http://www.xmission.com/~lawall
    "I'm not proud. We really haven't done everything we could to protect
    our customers. Our products just aren't engineered for security."
    --Microsoft VP in charge of Windows OS Development, Brian Valentine.

  • Lasse Reichstein Nielsen

    #2
    Re: window.open, Linux vs. Windows

    Raptor <me@attbi.com > writes:
    [color=blue]
    > I'm a complete Javascript n00b, using a snippet I found on the web.
    > I'll probably be buying a Javascript book. What's the authoritative
    > on-line resource for Javascript, like php.net is for PHP?[/color]

    I don't think there is *one* authoritative reference, mainly because
    there is more than one implementation of this thing called "Javascript ".
    I have some links at
    <URL:http://www.infimum.dk/HTML/references.html #ref_1_4>
    They are all more or less relevant. The first one is ofcourse the
    best (the FAQ for this group :).
    [color=blue]
    > This code works fine on Opera & Mozilla under Linux, but fails for
    > both Netscape & IE under Windows:[/color]

    "fails" is not a very imformative error report.

    Which Netscape? Netscape 4 and Netscape 6+ are completely unrelated
    browsers. In both cases, you can see Javascript errors in the Javascript
    console. It is activated by entering "javascript :" in the address line.
    [color=blue]
    > <script language="JavaS cript">[/color]

    In HTML 4 and later, the type attribute is required. A Javascript
    script tag is written:
    <script type="text/javascript">
    [color=blue]
    > <!--[/color]

    You don't need HTML comments in Javascript.
    [color=blue]
    > function smallWindow(URL , X, Y, Title)
    > {
    > var win = window.open(URL , Title,
    > 'width='+X+',he ight='+Y+',resi zable=1,scrollb ars=1');[/color]

    This looks reasonable (if you can accept that window.open isn't always
    working at all any more - popup-blockers are getting very popular and
    browsers on restricted platforms like mobile phones or WebTV can have
    problems with extra windows).

    No need for "var win =". It is a local variable in a function that
    ends right after the assignment, so the value is lost anyway.
    [color=blue]
    >
    > }
    > // -->
    > </script>
    >
    > <form name="form1" method="post" action="">
    > <html>
    > <head>[/color]

    You must have <html> or <head> before other HTML tags. The form
    tag right before it can only exist inside the body of the HTML
    page. That means that the browser inserts an implicit <body>,
    and the <html> and <head> are illegal tags inside the body.

    Try validating the generated HTML with, e.g., the W3C validator.
    [color=blue]
    > etc.
    > a ton of PHP code echoing HTML, including:[/color]

    Generally, in this group, we only care about the HTML code that is
    produced by the PHP, not the PHP code itself. If the page fails to
    work, there is a bug in the HTML, and it is easier to find the bug
    without the PHP around it.
    [color=blue]
    > echo '<a href="javascrip t:onclick=small Window(\'unitco nverter.php\',
    > \'250\', \'150\', \'Convert Units\');">';[/color]

    The generated HTML code would be:
    ---
    <a href="javascrip t:onclick=small Window('unitcon verter.php',
    '250', '150', 'Convert Units');">Unit Conversion Calculator</a>
    ---
    The FAQ recommends against using javascript:-URL's. Use the
    onclick handler instead and put a meaningful link in the href.

    You actually assign the return value of smallWindow (which is the
    undefined value) to a global variable called "onclick". Maybe you
    were trying to use the onclick handler?

    Spaces are not allowed in window names! This can be your real problem.

    I.e., use:
    ---
    <a href="unitconve rter.php" target="Convert Units"
    onclick="smallW indow(this.href ,'250','150',th is.target);retu rn false;">
    Unit Conversion Calculator</a>
    ---[color=blue]
    > I can open unitconverter.p hp stand-alone, as well as via a simple
    >
    > <a href="unitconve rter.php" target="new window">.[/color]

    Don't use spaces in window names!

    If you want to open a new window each time, use the target "_blank" instead.
    <URL:http://www.infimum.dk/HTML/JSwindows.html# ref_3_1>
    [color=blue]
    > It's only when I go through Javascript that it fails with nothing more
    > than a friendly "Error in page" message from IE, while Netscape is
    > mute.[/color]

    IE can give more informative error messages (not great, but better
    than "Error in page"). To enable it, uncheck the option:
    Tools > Options > Advanced > Browsing / Disable script debugging

    Alternatively, you can install the MS Script Debugger. I am not
    impressed by it, but it does show the line of the bug.

    Good luck.
    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Raptor

      #3
      Re: window.open, Linux vs. Windows

      Lasse Reichstein Nielsen wrote:[color=blue][color=green]
      >>This code works fine on Opera & Mozilla under Linux, but fails for
      >>both Netscape & IE under Windows:[/color]
      >
      >
      > "fails" is not a very imformative error report.[/color]

      That's all I knew at the time, being so new at this.

      (Snipped) a whole heaping crapload of tremendously useful information.
      Thank you very much, Lasse! :-)

      I'll be looking for opportunities to pay it forward.

      --
      --
      Lynn Wallace http://www.xmission.com/~lawall
      "I'm not proud. We really haven't done everything we could to protect
      our customers. Our products just aren't engineered for security."
      --Microsoft VP in charge of Windows OS Development, Brian Valentine.

      Comment

      Working...