I'm trying to open a blank window and write a message in it.
The following page works as expected in IE, but in Firefox the message
is not written:
<HTML>
<HEAD>
<TITLE>Document .write bug</TITLE>
<Script Language="JavaS cript">
function load() {
var w = window.open('', '','');
w.document.open ();
w.document.writ e('<html><body> <h1>hello</h1></body></html>');
w.document.clos e();
}
</Script>
</HEAD>
<BODY>
<H1>Document.wr ite bug</H1>
<a href="javascrip t:load()">Open Window</a>
</BODY>
</HTML>
I'm looking for the "cross-browser" way to achieve this effect.
Thanks for any hint. 7 2746
On Thu, 18 Nov 2004 11:56:47 +0100, Remi Bastide
<Du************ ****@irit.fr.du mmy> wrote:
[snip]
Please don't use tabs to format code when posting to Usenet. They usually
cause the text to wrap, making posts difficult to read. Instead, use
spaces (preferably two per level). <HTML>
Valid documents should have a DOCTYPE declaration. See
<URL:http://www.w3.org/TR/html4/struct/global.html#h-7.2> for more
information.
<HEAD> <TITLE>Document .write bug</TITLE> <Script Language="JavaS cript">
The language attribute has been deprecated for over six years. Use the
(required) type attribute instead:
<script type="text/javascript">
function load() { var w = window.open('', '',''); w.document.open (); w.document.writ e('<html><body> <h1>hello</h1></body></html>');
You should also make sure that you write valid HTML into a new document.
w.document.clos e(); }
[snip]
I'm looking for the "cross-browser" way to achieve this effect.
There's nothing IE-specific there, though I'd recommend your window.open
call included a name. I've seen problems when it's not included. Also,
don't specify a feature string if you're not specifying any features.
var w = window.open('', 'myWin');
The probable cause of this issue is that when you try to access the new
window and manipulate it, the browser hasn't finished preparing that
window.
One possible workaround is to initially open a document that signals when
it's loaded. Once that condition has been flagged, you can overwrite the
contents of the window.
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Michael Winter wrote:
[...] The probable cause of this issue is that when you try to access the new window and manipulate it, the browser hasn't finished preparing that window.
One possible workaround is to initially open a document that signals when it's loaded. Once that condition has been flagged, you can overwrite the contents of the window.
[...]
This is for the OP, but I'll add it after Michael's excellent advice...
Another way that works is to open the window, then write your HTML into
an array, then write it to the window. This should introduce just
enough of a delay to let the window open.
When writing large amounts of HTML, this can be the fastest method of
writing to the window - even faster than a concatenated string:
<script type="text/javascript">
function load() {
var w = window.open('', 'newWindow');
w.document.open ();
var a = [
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01',
' Transitional//EN" ',
'"http://www.w3.org/TR/html4/loose.dtd">',
'<html><head><t itle>No bugs</title>',
'</head><body>',
' <h1>It works</h1>',
'<p>Add lots more HTML here...</p>',
'</body></html>',
];
w.document.writ e(a.join(''));
w.document.clos e();
}
</script>
It is also much better for the link to do something useful rather than
just have JavaScript attached. If JS isn't working on the users
browser for some reason, they will click a link that just does
nothing.
Replace the href="javascrip t..." with a link to a useful page and put
the javascript into an onclick function:
<a href="aUsefulUR L.html" onclick="
load();
return false;
">Open Window</a>
If JS isn't working, the user will be taken to aUsefulURL.html , if it
is working, the new window will open (if not blocked) and return false;
will prevent the browser from following the link.
Cheers, Rob.
Michael Winter wrote:
[...] One possible workaround is to initially open a document that signals when it's loaded. Once that condition has been flagged, you can overwrite the contents of the window.
Mike
[...]
This is for the OP, but I'll add it after Michael's excellent advice...
Another way that works is to open the window, then write your HTML into
an array, then write it to the window. This should introduce just
enough of a delay to let the window open.
When writing large amounts of HTML, this can be the fastest method of
writing to the window - even faster than a concatenated string:
<script type="text/javascript">
function load() {
var w = window.open('', 'newWindow');
w.document.open ();
var a = [
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01',
' Transitional//EN" ',
'"http://www.w3.org/TR/html4/loose.dtd">',
'<html><head><t itle>No bugs</title>',
'</head><body>',
' <h1>It works</h1>',
'<p>Add lots more HTML here...</p>',
'</body></html>',
];
w.document.writ e(a.join(''));
w.document.clos e();
}
</script>
It is also much better for the link to do something useful rather than
just have JavaScript attached. If JS isn't working on the users
browser for some reason, they will click a link that just does nothing.
Replace the href="javascrip t..." with a link to a useful page and put
the javascript into an onclick function:
<a href="aUsefulUR L.html" onclick="
load();
return false;
">Open Window</a>
If JS isn't working, the user will be taken to aUsefulURL.html , if it
is working, the new window will open (if not blocked) and return false;
will prevent the browser from following the link.
Cheers, Rob.
"Remi Bastide" <Du************ ****@irit.fr.du mmy> wrote in message
news:sj******** *************** *********@4ax.c om... I'm trying to open a blank window and write a message in it. The following page works as expected in IE, but in Firefox the message is not written:
<HTML> <HEAD> <TITLE>Document .write bug</TITLE> <Script Language="JavaS cript"> function load() { var w = window.open('', '',''); w.document.open ();
w.document.writ e('<html><body> <h1>hello</h1></body></html>'); w.document.clos e(); } </Script> </HEAD> <BODY> <H1>Document.wr ite bug</H1> <a href="javascrip t:load()">Open Window</a> </BODY> </HTML>
I'm looking for the "cross-browser" way to achieve this effect. Thanks for any hint.
I just installed FireFox 1.0 and it worked for me.
I invoked your test page via: http://localhost/testpage.htm
as well as via: file:///C:\inetpub\wwwr oot\testpage.ht m
aka file:///C:%5Cinetpub%5C wwwroot%5Ctestp age.htm
Remi Bastide <Du************ ****@irit.fr.du mmy> wrote:
Thanks to all for the feedback.
I was using Firefox 1.0 Beta, after upgrading to 1.0 final, this
annoying behaviour appears to be gone.
Remi Bastide <Du************ ****@irit.fr.du mmy> wrote in message news:<sj******* *************** **********@4ax. com>... I'm trying to open a blank window and write a message in it. The following page works as expected in IE, but in Firefox the message is not written:
<HTML> <HEAD> <TITLE>Document .write bug</TITLE> <Script Language="JavaS cript"> function load() { var w = window.open('', '',''); w.document.open ();
w.document.writ e('<html><body> <h1>hello</h1></body></html>'); w.document.clos e(); } </Script> </HEAD> <BODY> <H1>Document.wr ite bug</H1> <a href="javascrip t:load()">Open Window</a> </BODY> </HTML>
I'm looking for the "cross-browser" way to achieve this effect. Thanks for any hint.
Not sure what you're referring to, working fine here. Here's a
superior (imo) alternative:
<HTML>
<HEAD>
<TITLE>Document .write bug</TITLE>
<Script Language="JavaS cript">
function getHTML()
{
return '<html><body><h 1>hello</h1></body></html>';
}
function load() {
var w = window.open('ja vascript:opener .getHTML()','w' ,'');
}
</Script>
</HEAD>
<BODY>
<H1>Document.wr ite bug</H1>
<a href="javascrip t:void load()">Open Window</a>
</BODY>
</HTML>
Like a favelet. Just a tip: if you're just learning this stuff, don't
get in the habit of naming global functions 'load' or other DOM-ish
names. Sooner or later you'll run afoul of an already named property.
Choose names that are likely to be unique. :)
RobG wrote: Another way that works is to open the window, then write your HTML into an array, then write it to the window. This should introduce just enough of a delay to let the window open.
When writing large amounts of HTML, this can be the fastest method of writing to the window - even faster than a concatenated string:
<script type="text/javascript"> function load() { var w = window.open('', 'newWindow'); w.document.open ();
var a = [ '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01', ' Transitional//EN" ', '"http://www.w3.org/TR/html4/loose.dtd">', '<html><head><t itle>No bugs</title>', '</head><body>', ' <h1>It works</h1>', '<p>Add lots more HTML here...</p>', '</body></html>', ];
w.document.writ e(a.join('')); w.document.clos e(); } </script>
Instead of working on some undetermined delay to "pause things long enough",
why not do it the correct way:
<script type="text/javascript">
function load() {
window.newWindo wHtml = [
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01',
' Transitional//EN" ',
'"http://www.w3.org/TR/html4/loose.dtd">',
'<html><head><t itle>No bugs</title>',
'</head><body>',
' <h1>It works</h1>',
'<p>Add lots more HTML here...</p>',
'</body></html>',
].join('\n');
var w = window.open('ja vascript:opener .newWindowHtml' ,'newWindow');
}
</script>
Alternatively:
function load() {
window.newWindo wHtml = [
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01',
' Transitional//EN" ',
'"http://www.w3.org/TR/html4/loose.dtd">',
'<html>',
'<head>',
'<title>Loader </title>',
'</head>',
'<body onload="opener. callBack(window );">',
'</body>',
'</html>',
].join('\n');
var w = window.open('ja vascript:opener .newWindowHtml' , 'newWin');
}
function callBack(w) {
w.document.open ();
w.document.writ e(...);
w.document.clos e();
}
</script>
The benefit of the second example is that the content output to the new
window is separated from the opening of the window.
--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Keith Thornhill |
last post by:
I'm trying to calculate the top and left distance from the side of the
browser of an object (either absolutely or relatively positioned) and i'm
running into a weird problem as i'm trying to make the code cross-browser.
normally i simply use the .offsetLeft/Top properties of the object to get my
numbers, and it is as simple as that. but in Firefox (v. 0.9.3), they both
return the value "8" no matter where the object appears on the page....
|
by: Cliff R. |
last post by:
Hi, I use a handy little Javascript Flash detection script on a number
of sites (copied below). Usually works great, but I just started
trying Firefox and it's not working. A few browsers are referenced in
the script so I presume that Firefox needs to be added somewhere --
does anyone know how I could update this to be supported by Firefox?
Thanks!
<SCRIPT TYPE="text/JavaScript">
|
by: Schraalhans Keukenmeester |
last post by:
I have no clue why below code (found it somewhere and altered it a wee
bit to my needs) will run without problem in both IE and Mozilla FireFox
1.0 but in the latter it takes up close to 100% cpu. It does check for
type of browser, and indeed all works fine apart from that ridiculous
amount of cpu taken.
If you want to see if it does so in your firefox/xp too, it's embedded
in my homepage (www.westerterp.com)
Can anyone explain why...
|
by: pantagruel |
last post by:
The following does not work in firefox:
<script defer="defer">
var x=document.getElementsByName("repositoryNamespace")
alert(x.length + " elements!")
|
by: Dan |
last post by:
Hi. I've got the following line of code which works fine in IE ...
line_1_numbers = document.getElementsByTagName
('table').rows (0).cells (0).innerText;
But it Firefox, it barks saying:
"Error: document.getElementsByTagName("table").rows is not a
function"
| |
by: lmarceglia |
last post by:
Hi,
I have this website that doesn't work in Firefox 1.5:
www.pianetaluca.com
The HTML source is:
<TITLE>PianetaLuca</TITLE>
</HEAD>
|
by: evgenyg |
last post by:
Hello !
We have the following situation - when Ajax request is sent what's
being returned by the server is usually an XML (which is used for DOM
updates) but sometimes it's HTML which is a whole new page that should
replace an existing one. I.e when we issue an Ajax request we don't
know what will be returned and analyze the response to act accordingly.
Now, the way to replace the current document with a new one used to be
easy and...
|
by: laramie.hartmann |
last post by:
I have a script (see below) that accesses a XML file and displays the
contents through a series of document.write calls. This all works fine
in IE, but not at all in Firefox. I get no errors in the javascript
console, but when I try to load the elements by tag name and look at
the length it is always 0 as if no elements have been added. Any
suggestions are greatly appreciated as I've been stuck on this for a
while now.
Thanks,
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |