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="JavaScript">[/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+',height='+Y+',resizable=1,scrollbars=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="javascript
:onclick=smallWindow(\'unitconvert er.php\',
> \'250\', \'150\', \'Convert Units\');">';[/color]
The generated HTML code would be:
---
<a href="javascript
:onclick=smallWindow('unitconverte r.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="unitconverter.php" target="ConvertUnits"
onclick="smallWindow(this.href,'250','150',this.ta rget);return false;">
Unit Conversion Calculator</a>
---[color=blue]
> I can open unitconverter.php stand-alone, as well as via a simple
>
> <a href="unitconverter.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/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'