newbie about window.open

H

hakim

Hi,

My code:

<html>

<head>
<title>Test</title>

<script type="text/javascript">

function schreibschrift () {
var fenster = window.open("","neu","");
fenster.document.write('Hallo');
}
</script>
</head>


<body>
<table>
<script type="text/javascript">
schreibschrift();
</script>
</table>
</body>

</html>

When the new Window pops up, then it never stops to load. How I can
stop the loading of the window. It loads and loads...

Thanks...
 
H

hakim

Problem solved...

in function schreibschrift:

fenster.document.open();
fenster.document.write('Hallo');
fenster.document.close();

Bye...
 
R

Robi

hakim wrote in message
[...]
<body>
<table>
<script type="text/javascript">
schreibschrift();
</script>
</table>
</body>

Hakim, just out of pure curiosity,

why do you have the script tag inside an empty table tag?

you could just as easily write:

<head>
<title>Test</title>
<script type="text/javascript">
function schreibschrift () {
var fenster = window.open("","neu","");
// fenster.document.open(); <--- you don't need this
fenster.document.write('Hallo');
fenster.document.close();
}
document.onload = schreibschrift();
</script>
</head>

et voila, your "hallo" window opens as soon as the "test" document is loaded.

http://developer.mozilla.org/en/docs/DOM:document.write#Notes
"Writing to a document that has already loaded without calling document.open
will automatically perform a document.open call. Once you have finished
writing, it is recommended to call document.close, to tell the browser to
finish loading the page."
 
R

Robi

Robi wrote:

[...]
you could just as easily write:

<head>
<title>Test</title>
<script type="text/javascript">
function schreibschrift () {
var fenster = window.open("","neu","");
// fenster.document.open(); <--- you don't need this
fenster.document.write('Hallo');
fenster.document.close();
}
document.onload = schreibschrift();
</script>
</head>

et voila, your "hallo" window opens as soon as the "test" document is loaded.
[...]

I forgot to mention:
- if you're authoring a webpage, try to avoid using window.open() for different
reasons.
1. many people don't like popups.
2. many people use "tabbed" browsers like Firefox and Opera and won't
appreciate a new window popping up.
3. opening a new window uses resources (CPU and RAM).

if you ask, how can I open a new page in a new tab using javascript, I have
to pass and say "Sorry, no Idea".
 
H

hakim

Robi schrieb:

Hakim, just out of pure curiosity,

why do you have the script tag inside an empty table tag?
Because I need at that point a table, but that code wasn't important
for the discribed problem.
you could just as easily write:

<head>
<title>Test</title>
<script type="text/javascript">
function schreibschrift () {
var fenster = window.open("","neu","");
// fenster.document.open(); <--- you don't need this
fenster.document.write('Hallo');
fenster.document.close();
}
document.onload = schreibschrift();
</script>
</head>

No I couldn't because then the lines would brake. And I don't want it
in that case. Originaly there is a whole Text and not only the word
'Hallo'.

Achim
 
V

vallini

===
why do you have the script tag inside an empty table tag?
===

He probably writes dynamically the very same contents of the TR and TD
tags, arguably a table whose cells and rows length are determined by
outside variables.
I guess, at least.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top