By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,572 Members | 946 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,572 IT Pros & Developers. It's quick & easy.

window.open, Linux vs. Windows

P: n/a
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="JavaScript">
<!--
function smallWindow(URL, X, Y, Title)
{
var win = window.open(URL, Title,
'width='+X+',height='+Y+',resizable=1,scrollbars=1 ');
}
// -->
</script>

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

echo '<a href="javascript:onclick=smallWindow(\'unitconvert er.php\',
\'250\', \'150\', \'Convert Units\');">';
echo 'Unit Conversion Calculator';
echo '</a>';
I can open unitconverter.php stand-alone, as well as via a simple

<a href="unitconverter.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.

Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Raptor <me@attbi.com> writes:
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 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 :).
This code works fine on Opera & Mozilla under Linux, but fails for
both Netscape & IE under Windows:
"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.
<script language="JavaScript">
In HTML 4 and later, the type attribute is required. A Javascript
script tag is written:
<script type="text/javascript">
<!--
You don't need HTML comments in Javascript.
function smallWindow(URL, X, Y, Title)
{
var win = window.open(URL, Title,
'width='+X+',height='+Y+',resizable=1,scrollbars=1 ');
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.

}
// -->
</script>

<form name="form1" method="post" action="">
<html>
<head>
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.
etc.
a ton of PHP code echoing HTML, including:
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.
echo '<a href="javascript:onclick=smallWindow(\'unitconvert er.php\',
\'250\', \'150\', \'Convert Units\');">';
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>
--- I can open unitconverter.php stand-alone, as well as via a simple

<a href="unitconverter.php" target="new window">.
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>
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.


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 - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
Lasse Reichstein Nielsen wrote:
This code works fine on Opera & Mozilla under Linux, but fails for
both Netscape & IE under Windows:

"fails" is not a very imformative error report.


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.

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.