Client Create Dynamic Window/HTML

Discussion in 'Javascript' started by MC, Aug 9, 2011.

  1. MC

    MC Guest

    Doing the following will open a new window and get a page:'/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, Aug 9, 2011
    1. Advertisements

  2. MC

    Tim Streater Guest

    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.
    Tim Streater, Aug 9, 2011
    1. Advertisements

  3. MC

    MC Guest

    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',
    var doc = document.implementation.createDocument('', 'html', doctype);

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

    PS, opens but it does not use doc
    MC, Aug 9, 2011
  4. MC

    MC Guest

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

    MC, Aug 10, 2011
  5. MC

    MC Guest

    This works but has no doctype tag:

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

    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, Aug 10, 2011
  6. MC

    MC Guest

    Seems as if I have stumped the masters...
    MC, Aug 12, 2011
  7. wrote:
    That is a fallacy.

    Thomas 'PointedEars' Lahn, Aug 12, 2011
  8. MC

    MC Guest

    That your stumped or your a master? drumroll....
    MC, Aug 12, 2011
  9. 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:'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.

    Lasse Reichstein Nielsen, Aug 12, 2011
  10. MC

    MC Guest

    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, 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
    MC, Aug 12, 2011
  11. MC

    BootNic Guest

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

    remove the space from "Quote Proposal"
    var docType = '<!DOCTYPE HTML PUBLIC' +
    ' "-//W3C//DTD HTML 4.01 Transitional//EN"' +
    ' "">';

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

    var winProposal =;;
    winProposal.document.write(docType + outSource);

    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*

    Version: GnuPG v1.4.11 (GNU/Linux)

    -----END PGP SIGNATURE-----
    BootNic, Aug 12, 2011
  12. 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 `<\/').
    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.

    Thomas 'PointedEars' Lahn, Aug 13, 2011
  13. 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).
    Jukka K. Korpela, Aug 13, 2011
  14. 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.
    But the HTML 4.01 Specification does.

    Thomas 'PointedEars' Lahn, Aug 13, 2011
  15. 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.
    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.
    Jukka K. Korpela, Aug 13, 2011
  16. You are trolling. "one" does not refer to to the word "error" here, it
    refers to "helpful comment".
    Yes, it can, and it does:


    Thomas 'PointedEars' Lahn, Aug 13, 2011
  17. MC

    Evertjan. Guest

    Thomas 'PointedEars' Lahn wrote on 13 aug 2011 in comp.lang.javascript:
    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.

    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Aug 13, 2011
  18. MC

    Evertjan. Guest

    Jukka K. Korpela wrote on 13 aug 2011 in comp.lang.javascript:
    Nonsense, usenet postings content has no applicable copyright.
    Evertjan., Aug 13, 2011
  19. 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.)
    Jukka K. Korpela, Aug 13, 2011
  20. In most jurisdictions copyright is automatic. How does Usenet negate
    these automatic rights?
    Ben Bacarisse, Aug 13, 2011
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.
Similar Threads
There are no similar threads yet.