Client Create Dynamic Window/HTML

M

MC

Doing the following will open a new window and get a page:
window.open('/mypage.html'...

I would like to open a new window but fill it with dynamic content from the
client current window DOM. I can't seem to find an example of how to do
that. Does anyone know how or have a link to a reference?

Thank you,
MC
 
T

Tim Streater

MC said:
Doing the following will open a new window and get a page:
window.open('/mypage.html'...

I would like to open a new window but fill it with dynamic content from the
client current window DOM. I can't seem to find an example of how to do
that. Does anyone know how or have a link to a reference?

What sort of content? If you have an element in the original window that
you'd like your new window to have access to, then something like:

ptr = opener.document.getElementById("id-of-element");

gets you a pointer to it.
 
M

MC

Ok, this will create a document with two childNodes
(0) document type
(1) html element

var doctype = document.implementation.createDocumentType('html',
'-//W3C//DTD HTML 4.01 Transitional//EN',
'http://www.w3.org/TR/html4/loose.dtd');
var doc = document.implementation.createDocument('', 'html', doctype);

How do I open a window using this or can I?

MC
PS, window.open(doc) opens but it does not use doc
 
M

MC

I don't care about the content...I need to use js to open a window with a
doctype tag. window.open does not do that.

MC
 
M

MC

This works but has no doctype tag:

var winProposal = window.open("", "Quote Proposal",
"status=1,width=600,height=800");
var nodeHTML = {};
var nodeHEAD = {};
var nodeBODY = {};
for (var i=0; i < winProposal.document.childNodes.length; i++) {
if (winProposal.document.childNodes.nodeType == 1) nodeHTML =
winProposal.document.childNodes;
}
for (var i=0; i < nodeHTML.childNodes.length; i++) {
if (nodeHTML.childNodes.nodeName == 'HEAD') nodeHEAD =
nodeHTML.childNodes;
if (nodeHTML.childNodes.nodeName == 'BODY') nodeBODY =
nodeHTML.childNodes;
}


nodeBODY.innerHTML = "some junk here";

Is there a better way? I would really like to create the html, populate a
document object, then open the window and display it.

MC
 
L

Lasse Reichstein Nielsen

MC said:
Doing the following will open a new window and get a page:
window.open('/mypage.html'...
I would like to open a new window but fill it with dynamic content from the
client current window DOM.

So, you need to copy the DOM to a different document.
That takes extra work, since DOM elements always belong to the document that
created them. I.e., you need to mirror the content in the other window.

For that you can use document.importNode.

You definitly need the other window to be loaded before you can start
doing anything. I would open it as:

window.open('javascript:"<body><script>document.body.appendChild(document.importNode(opener.document.getElementById(\'id_of_element_to_copy\'), true))</script></body>"')

Ofcourse, that uses standard DOM features, so it won't work in IE.

Alternatively, you could just get the innerHTML containing the content
you want to move, and add it as innerHTML in the receiving page.
I can't seem to find an example of how to do
that. Does anyone know how or have a link to a reference?

Why take content from the DOM of the opening page instead of just taking
some data that can be used to build a DOM on both pages. I.e., separate
your data model from your display technology, and only reuse the data.

/L
 
M

MC

Lasse Reichstein Nielsen said:
So, you need to copy the DOM to a different document.
That takes extra work, since DOM elements always belong to the document
that
created them. I.e., you need to mirror the content in the other window.

For that you can use document.importNode.

You definitly need the other window to be loaded before you can start
doing anything. I would open it as:


window.open('javascript:"<body><script>document.body.appendChild(document.importNode(opener.document.getElementById(\'id_of_element_to_copy\'),
true))</script></body>"')

Ofcourse, that uses standard DOM features, so it won't work in IE.

Alternatively, you could just get the innerHTML containing the content
you want to move, and add it as innerHTML in the receiving page.


Why take content from the DOM of the opening page instead of just taking
some data that can be used to build a DOM on both pages. I.e., separate
your data model from your display technology, and only reuse the data.

/L

I know how to manipulate and copy content, no problem. What I am trying to
do is load a document, then open it, instead of using the window.open, then
copying/filling the content. The content is coming from the DOM, and cloning
content. Its pretty neat, we are essentially creating a print report based
on screen content and DOM, without having to make a roundtrip to the server.
I take it from your comment that you think filling, then opening a document
is not possible?

Thanks MC
 
B

BootNic

On Wed, 10 Aug 2011 15:36:43 -0500

[snip]
var winProposal = window.open("", "Quote Proposal",
"status1,width=600,height=800");

remove the space from "Quote Proposal"
[snip]
Is there a better way? I would really like to create the html, populate a
document object, then open the window and display it.

var docType = '<!DOCTYPE HTML PUBLIC' +
' "-//W3C//DTD HTML 4.01 Transitional//EN"' +
' "http://www.w3.org/TR/html4/loose.dtd">';

var outSource = '<html><head><title>Out Source</title>' +
'<body><h1>Out Source</h1></body></head></html>';

var winProposal = window.open();

winProposal.document.open();
winProposal.document.write(docType + outSource);
winProposal.document.close();


--
BootNic Fri Aug 12, 2011 06:41 pm
"This seems like a case where we need to shoot the messenger."
*Charlie Kaufman on Cypherpunks list*

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAk5Fq/8ACgkQmo2774GZ7ql7FwCcCr7kZFTMYAipOgEF5E5yifBx
IncAoJf8InpwOXR/3QVzRM9v2w55HPb+
=HQiV
-----END PGP SIGNATURE-----
 
T

Thomas 'PointedEars' Lahn

BootNic said:
var docType = '<!DOCTYPE HTML PUBLIC' +
' "-//W3C//DTD HTML 4.01 Transitional//EN"' +
' "http://www.w3.org/TR/html4/loose.dtd">';

var outSource = '<html><head><title>Out Source</title>' +
'<body><h1>Out Source</h1></body></head></html>';

For Valid HTML being generated, which appears to be the intention, the META
element declaring the document's character encoding ("charset") is missing,
as there is no higher-level protocol to specify it here.

It should also be noted that if this code is used within an HTML document,
all ETAGO delimiters (`</') need to be escaped (e. g., as `<\/').
var winProposal = window.open();

winProposal.document.open();
winProposal.document.write(docType + outSource);
winProposal.document.close();

This is error-prone, as `winProposal.document' does not need to be
available, then. The most efficient, reliable, and compatible way is to
refer to a resource which then generates its dynamic content dynamically.


PointedEars
 
J

Jukka K. Korpela

13.8.2011 15:45 said:
For Valid HTML being generated, which appears to be the intention, the META
element declaring the document's character encoding ("charset") is missing,
as there is no higher-level protocol to specify it here.

Your lecture has little to do with the question asked, and at least this
part (I don't really read most of your lectures) is simply wrong. No
HTML DTD imposes a validity requirement like that, and no DTD _could_ do
that (among other things, because DTDs cannot make anything conditional
depending on higher-level protocols).
 
T

Thomas 'PointedEars' Lahn

Jukka said:
Your lecture has little to do with the question asked,

It is not a lecture, it is a helpful comment. And it was not the only one
in my posting, which you conveniently snipped, so you could dwell on this.
Loser.
and at least this part […] is simply wrong. No HTML DTD imposes a validity
requirement like that,

But the HTML 4.01 Specification does.


PointedEars
 
J

Jukka K. Korpela

13.8.2011 16:13 said:
And it was not the only one
in my posting, which you conveniently snipped,

Maybe it was not the only error, but the one I commented on. By Usenet
practices and by normal practices in human discussion, as well as
according to applicable copyright legislation, one should only quote the
part that is relevant to one's own comments. By criticizing that, you
indicate that you are either a novice or a troll.
and at least this part […] is simply wrong. No HTML DTD imposes a validity
requirement like that,

But the HTML 4.01 Specification does.

No it does not and it cannot. The specification defines HTML as an
application of SGML (though this has never been reality in
_implementations_, except in your dreams), so it cannot just redefine
validity, an SGML term.

(Besides, if you actually tried to find a requirement for a meta tag to
specify encoding, you would fail. The spec _could_ impose such a
requirement, and one might even expect it does - as a conformance
requirement, not validity issue - but it doesn't.)

So if you want to lecture on issues like this, learn the concepts, study
the facts, and find the right group (and thread) first.
 
T

Thomas 'PointedEars' Lahn

Jukka said:
13.8.2011 16:13 said:
And it was not the only one in my posting, which you conveniently
snipped,

Maybe it was not the only error, […]

You are trolling. "one" does not refer to to the word "error" here, it
refers to "helpful comment".
and at least this part […] is simply wrong. No HTML DTD imposes a >
validity requirement like that,

But the HTML 4.01 Specification does.

No it does not and it cannot.

Yes, it can, and it does:

<http://www.w3.org/TR/html401/charset.html#h-5.2.2>


PointedEars
 
E

Evertjan.

Thomas 'PointedEars' Lahn wrote on 13 aug 2011 in comp.lang.javascript:
The most efficient, reliable, and compatible way is to
refer to a resource which then generates its dynamic content dynamically.

Wouldn't "statical generation" be a contradictio in terminis?

And if not, how would you statically gerenate dynamic content?

Your referred resource should be increadably resourseful,
compatible "serverside coding" being a dirty word.

-
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
E

Evertjan.

Jukka K. Korpela wrote on 13 aug 2011 in comp.lang.javascript:
Maybe it was not the only error, but the one I commented on. By Usenet
practices and by normal practices in human discussion, as well as
according to applicable copyright legislation, one should only quote the
part that is relevant to one's own comments

Nonsense, usenet postings content has no applicable copyright.
 
J

Jukka K. Korpela

13.8.2011 17:16 said:
and at least this part […] is simply wrong. No HTML DTD imposes a>
validity requirement like that,

But the HTML 4.01 Specification does.

No it does not and it cannot.

Yes, it can, and it does:

<http://www.w3.org/TR/html401/charset.html#h-5.2.2>

So you decided to ignore my advice on learning the concepts, studying
the facts, and selecting the right group first.

That section of HTML 4.01 Specification does not (and could not) make a
meta element required in some situations as a validity requirement. It
does not even make it required otherwise.

To conclude, your claim was not only irrelevant to the topic discussed;
it was also off-topic for the group and fundamentally incorrect.

Followups set. (As a matter of principle. A revealed troll probably
ignores that, of course.)
 
B

Ben Bacarisse

Evertjan. said:
Jukka K. Korpela wrote on 13 aug 2011 in comp.lang.javascript:


Nonsense, usenet postings content has no applicable copyright.

In most jurisdictions copyright is automatic. How does Usenet negate
these automatic rights?
 

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
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top