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:
    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
    MC, Aug 9, 2011
    #1
    1. Advertising

  2. MC

    Tim Streater Guest

    In article <d2c3b$4e4198e5$4b58d23d$>,
    "MC" <mica[removethis]@aisus.com> wrote:

    > 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.

    --
    Tim

    "That excessive bail ought not to be required, nor excessive fines imposed,
    nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
    Tim Streater, Aug 9, 2011
    #2
    1. Advertising

  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',
    '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
    MC, Aug 9, 2011
    #3
  4. MC

    MC Guest

    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
    MC, Aug 10, 2011
    #4
  5. MC

    MC Guest

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

    MC Guest

    Wow,
    Seems as if I have stumped the masters...
    MC, Aug 12, 2011
    #6
  7. wrote:

    > Wow,
    > Seems as if I have stumped the masters...


    That is a fallacy.


    PointedEars
    --
    Use any version of Microsoft Frontpage to create your site.
    (This won't prevent people from viewing your source, but no one
    will want to steal it.)
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
    Thomas 'PointedEars' Lahn, Aug 12, 2011
    #7
  8. MC

    MC Guest

    What?
    That your stumped or your a master? drumroll....
    MC, Aug 12, 2011
    #8
  9. "MC" <mica[removethis]@aisus.com> writes:

    > 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
    --
    Lasse Reichstein Holst Nielsen
    'Javascript frameworks is a disruptive technology'
    Lasse Reichstein Nielsen, Aug 12, 2011
    #9
  10. MC

    MC Guest

    "Lasse Reichstein Nielsen" <> wrote in message
    news:...
    > "MC" <mica[removethis]@aisus.com> writes:
    >
    >> 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
    > --
    > Lasse Reichstein Holst Nielsen
    > 'Javascript frameworks is a disruptive technology'
    >


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

    BootNic Guest

    On Wed, 10 Aug 2011 15:36:43 -0500
    "MC" <mica[removethis]@aisus.com> wrote:

    [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-----
    BootNic, Aug 12, 2011
    #11
  12. BootNic wrote:

    > "MC" <mica[removethis]@aisus.com> wrote:
    >> 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>';


    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
    --
    Anyone who slaps a 'this page is best viewed with Browser X' label on
    a Web page appears to be yearning for the bad old days, before the Web,
    when you had very little chance of reading a document written on another
    computer, another word processor, or another network. -- Tim Berners-Lee
    Thomas 'PointedEars' Lahn, Aug 13, 2011
    #12
  13. 13.8.2011 15:45, Thomas 'PointedEars' Lahn wrote:

    > 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).

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Jukka K. Korpela, Aug 13, 2011
    #13
  14. Jukka K. Korpela wrote:

    > 13.8.2011 15:45, Thomas 'PointedEars' Lahn wrote:
    >> 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,


    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
    --
    Use any version of Microsoft Frontpage to create your site.
    (This won't prevent people from viewing your source, but no one
    will want to steal it.)
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
    Thomas 'PointedEars' Lahn, Aug 13, 2011
    #14
  15. 13.8.2011 16:13, Thomas 'PointedEars' Lahn wrote:

    > 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.

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Jukka K. Korpela, Aug 13, 2011
    #15
  16. Jukka K. Korpela wrote:

    > 13.8.2011 16:13, Thomas 'PointedEars' Lahn wrote:
    >> 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
    --
    var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
    Thomas 'PointedEars' Lahn, Aug 13, 2011
    #16
  17. MC

    Evertjan. Guest

    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)
    Evertjan., Aug 13, 2011
    #17
  18. MC

    Evertjan. Guest

    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.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Aug 13, 2011
    #18
  19. 13.8.2011 17:16, Thomas 'PointedEars' Lahn wrote:

    >>>> 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.)

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Jukka K. Korpela, Aug 13, 2011
    #19
  20. "Evertjan." <> writes:

    > 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.


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

    --
    Ben.
    Ben Bacarisse, Aug 13, 2011
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Tm92aWNl?=
    Replies:
    2
    Views:
    6,617
    Alan Ferrandiz Langley
    Jun 9, 2004
  2. =?Utf-8?B?TmljayBQb3VsaXM=?=

    Forms in Modal IE Window create a new window on postback!

    =?Utf-8?B?TmljayBQb3VsaXM=?=, Jun 2, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    3,924
    Jeffrey Todd
    Jun 3, 2005
  3. Socrat
    Replies:
    1
    Views:
    400
    Phlip
    Jun 22, 2004
  4. webServiceHelp
    Replies:
    0
    Views:
    372
    webServiceHelp
    Nov 27, 2006
  5. webServiceHelp
    Replies:
    0
    Views:
    395
    webServiceHelp
    Nov 28, 2006
Loading...

Share This Page