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

Problems with Window.Open()

P: n/a
I just spent the whole day on solving this problem but still have no
success.

This is what i do:
ModalDialog.window = window.open("",
"error",
"toolbar=no,width=" + iWidth + ",height="
+ (iHeight + 100) + "," +
"left=" + cx + ",top=" + cy + "," +
"status=no,resizable=no,modal=yes,dialog=yes") ;
ModalDialog.window.document.write(wt);
ModalDialog.window.document.close();

wt variable contains the actual HTML to be shown:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Izpis</title>
<link rel="stylesheet" type="text/css" href="/inc/styles.css"/>
<link rel="stylesheet" type="text/css" href="/inc/datepicker.css"/>
<script type="text/javascript" src="/inc/xmlextras.php"></script>
<script type="text/javascript" src="/inc/datepicker.php"></script>
............
</head>
<body onblur="javascript:focusMe()">
............
<div style="height: 120px; width: 100%; overflow: auto; background-image:
url(/images/layout.jpg); color: white">
............
<script type="text/javascript">
var d = new Date();
var dp = new DatePicker(d, true); <---------------------- Error:
DatePicker is undefined
............
</script>
</div>
............
</body>
</html>

This HTML validates OK except for the onblur event of the body tag.
Note the marked line where i try to construct a new DatePicker object.
It works like a charm in FireFox, but not in IE.
If I save the HTML (wt variable) in test.html, it will work correctly (It's
the SAME HTML). It will also work correctly if used in standard page,
generated by php, but NOT when used with Window.Open().

What am I doing wrong?

Any help would be greatly appreciated.

Thanks,
Jure
Oct 6 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Jure Erznoznik wrote:
I just spent the whole day on solving this problem but still have no
success.

This is what i do:
ModalDialog.window = window.open("",
"error",
"toolbar=no,width=" + iWidth + ",height="
+ (iHeight + 100) + "," +
"left=" + cx + ",top=" + cy + "," +
"status=no,resizable=no,modal=yes,dialog=yes") ;
ModalDialog.window.document.write(wt);
ModalDialog.window.document.close();

wt variable contains the actual HTML to be shown:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Izpis</title>
<link rel="stylesheet" type="text/css" href="/inc/styles.css"/>
<link rel="stylesheet" type="text/css" href="/inc/datepicker.css"/>
<script type="text/javascript" src="/inc/xmlextras.php"></script>
<script type="text/javascript" src="/inc/datepicker.php"></script>
...........
</head>
<body onblur="javascript:focusMe()">
Ditch the javascript pseudo protocol, it is unnecessary.

<body onblur="focusMe();">

...........
<div style="height: 120px; width: 100%; overflow: auto; background-image:
url(/images/layout.jpg); color: white">
...........
<script type="text/javascript">
var d = new Date();
var dp = new DatePicker(d, true); <---------------------- Error:


Presumably DatePicker is defined in the datepicker.php script, but the
script very likely hasn't loaded yet. Put this script element right at
the bottom of the page or run it from window/body onload.

[...]

--
Rob
Oct 6 '05 #2

P: n/a
> Ditch the javascript pseudo protocol, it is unnecessary.

<body onblur="focusMe();">
I'm sorry, i don't understand. How else would i call focusMe() if not in
onblur event?
What exactly do you mean by javascript pseudo protocol?
Presumably DatePicker is defined in the datepicker.php script, but the
script very likely hasn't loaded yet. Put this script element right at
the bottom of the page or run it from window/body onload.


You are right, it is defined in datepicker.php.
Your assumption about loading seems very plausible.
The script is practically at the bottom.
I will try running it from onload event, will post results.

Thanks,
Jure
Oct 6 '05 #3

P: n/a
Jure Erznoznik wrote:
Ditch the javascript pseudo protocol, it is unnecessary.

<body onblur="focusMe();">

I'm sorry, i don't understand. How else would i call focusMe() if not in
onblur event?


Using onblur() to keep a window in focus isn't pleasant for users, but
it's your site I suppose...
What exactly do you mean by javascript pseudo protocol?
Element attributes for intrinsic events expect JavaScript by default.
Using a protocol name (like 'javascript:') is intended to tell the
browser that a non-default script language is being used. That useful
if you are using, say, VBScript in your pages.

Since that is so rare, for any of the 'on' events (onclick, onblur,
onmouseover, etc.) just put the javascript in the attribute.

Where the pseudo-protocol is required is when script is the value of an
attribute where it is not expected by default, e.g. for an href attribute:

<a href="javascript:showPic();" ... >

But that is universally disliked. If an A element is to be bastardised
that way, it should use an onclick event and the href should actually do
something useful. The onclick should cancel the navigation by returning
false:

<a href="someUsefulURL.html" onclick="showPic();return false;" ...>

Presumably DatePicker is defined in the datepicker.php script, but the
script very likely hasn't loaded yet. Put this script element right at
the bottom of the page or run it from window/body onload.

You are right, it is defined in datepicker.php.
Your assumption about loading seems very plausible.
The script is practically at the bottom.
I will try running it from onload event, will post results.

Thanks,
Jure

--
Rob
Oct 6 '05 #4

P: n/a
Jure Erznoznik wrote:
I just spent the whole day on solving this problem but still have no
success.

This is what i do:
ModalDialog.window = window.open("", <snip>

When a window is opened with an empty string as its URL parameter the
browser uses "about:blank" (or an equivalent) as the URL of the new
window.
<script type="text/javascript" src="/inc/xmlextras.php"></script>
<script type="text/javascript" src="/inc/datepicker.php"></script>

<snip>

If you document.write a relative URL into a window that has as its base
URL "about:blank" what would be the absolute URL from which the JS file
is requested?

Richard.
Oct 6 '05 #5

P: n/a
Lee
RobG said:
Where the pseudo-protocol is required is when script is the value of an
attribute where it is not expected by default, e.g. for an href attribute:

<a href="javascript:showPic();" ... >

But that is universally disliked. If an A element is to be bastardised
that way, it should use an onclick event and the href should actually do
something useful. The onclick should cancel the navigation by returning
false:

<a href="someUsefulURL.html" onclick="showPic();return false;" ...>


I'm going to pick a few nits.

It's really only correct to call it a pseudo-protocol when it is
used in an URI, as in the HREF attribute value. In other cases,
it's really just a statement label.

The javascript: pseudo-protocol does have some uses when used as
intended, rather than for its side-effect of executing a function.
The intended use is that the current page contents are replaced
by the value of the evaluated Javascript expression. For example:

<a href="javascript:'<html>Hello, world!</html>'">test</a>

or

window.open("javascript:opener.myPageGenerator('be ta')");

This usage does have some significant limitations. Some browsers
may not trust that the generated page is from the same domain, so
it shouldn't be used too casually.

Oct 7 '05 #6

P: n/a
> Using onblur() to keep a window in focus isn't pleasant for users, but
it's your site I suppose...


Well, this is actually a parameter input dialog. I would much rather that
browsers supported REAL dialogs, but since they don't, i have to do it this
way. It only does its job once in FF though. Seems FF has a safeguard
against malware that would prevent user from interacting with the browser
:). In IE it works fine, but the windows clicked still gets the event
(MouseDown), but no MouseUp. It's kinda funny watching a selection start
appearing after this :)
Anyway, the way it's working now, code is only intended to show the user it
would be wise to fill out the parameters for the operation he / she
requested, nothing more.
What exactly do you mean by javascript pseudo protocol?


Element attributes for intrinsic events expect JavaScript by default.
Using a protocol name (like 'javascript:') is intended to tell the browser
that a non-default script language is being used. That useful if you are
using, say, VBScript in your pages.


Thanks for the info. I don't really have much theoretical knowledge about
this.

About the onload a.k.a. DatePicker is undefined:
Thank you very much. The stuff works now when called from onload event :)

Jure
Oct 7 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.