Embedded HTML in frameset - is it possible?

Discussion in 'HTML' started by Alex Molochnikov, Jan 21, 2005.

  1. Is there any way to embed the HTML code inside FRAMESET? Something like
    this:

    <frameset cols="50%,*">
    <frame src=" ... HTML code for the frame ... ">
    <frame src="Frame2.html" name="main">
    </frameset><noframes></noframes>

    I tried using a Javascript function that returns the HTML text, as in the
    following code:

    <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
    <html>
    <head> <title>Frame 1</title>
    <script type="text/javascript">
    function myFunction()
    {
    return ("<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">
    <html>
    <head>
    <title>Frame 1</title>
    </head>
    <body>
    <H2>Frame 1</H2>
    </body>
    </html>
    ")
    }
    </script>
    </head>
    <frameset cols="50%,*">
    <frame src=myFunction() name="toc">
    <frame src="Frame2.html" name="main">
    </frameset><noframes></noframes>
    </html>

    but the browser shows the "The page cannot be displayed" for the first
    frame.

    I am trying to find a way to generate a page from the Java servlet that
    would contain a hidden (0-width) frame and a fully visible frame with some
    dynamic content.

    I will appreciate any clues.

    Alex Molochnikov
     
    Alex Molochnikov, Jan 21, 2005
    #1
    1. Advertising

  2. Alex Molochnikov

    Ben Measures Guest

    Firstly, it's usenetiquette to set a "Followup" when posting to multiple
    newsgroups. [Followup set.]

    Alex Molochnikov wrote:
    > Is there any way to embed the HTML code inside FRAMESET? Something like
    > this:
    >
    > <frameset cols="50%,*">
    > <frame src=" ... HTML code for the frame ... ">
    > <frame src="Frame2.html" name="main">
    > </frameset><noframes></noframes>


    Many people (including myself) recommend dropping frames for CSS. Frames
    have many disadvantages with no supporting advantage.

    http://www.html-faq.com/htmlframes/?framesareevil

    --
    Ben M.
     
    Ben Measures, Jan 21, 2005
    #2
    1. Advertising

  3. Alex Molochnikov wrote:

    > Is there any way to embed the HTML code inside FRAMESET?
    > <frameset cols="50%,*">
    > <frame src=myFunction() name="toc">


    You can use
    <frame src="javascript:parent.myFunction()" name="toc">
    if you make sure that myFunction returns a string with HTML but of
    course that will only work then if the browser supports JavaScript and
    the user has it enabled so on the web in general that is not a good
    idea, even if you want to use frames.
    And even then there are issues in some browsers, Opera 7 for instance
    might give you access denied errors or similar when cross frame
    scripting is used later.

    If you really want to set the frame content with script then it is safer
    to have a function write to that frame e.g.
    function initFrame () {
    var frameDoc = window.frames.toc;
    frameDoc.document.open();
    frameDoc.document.write('html goes here');
    frameDoc.document.close();
    }

    <frameset onload="initFrame();" ...>
    <frame src="fallback.html" name="toc">

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 21, 2005
    #3
  4. Alex Molochnikov wrote:
    > Is there any way to embed the HTML code inside FRAMESET?


    No.

    [snip]

    > I am trying to find a way to generate a page from the Java servlet that
    > would contain a hidden (0-width) frame and a fully visible frame with some
    > dynamic content.


    The purpose of frames (which is generally vastly outweighed by their
    flaws and disadvantages) is to display content from multiple documents.
    If you don't want to do that, why are you using frames at all? What is
    meant to go in this "hidden" frame?
     
    Harlan Messinger, Jan 21, 2005
    #4
  5. Martin Honnen wrote:
    >
    >
    > Alex Molochnikov wrote:
    >
    >> Is there any way to embed the HTML code inside FRAMESET? <frameset
    >> cols="50%,*">
    >> <frame src=myFunction() name="toc">

    >
    >
    > You can use
    > <frame src="javascript:parent.myFunction()" name="toc">
    > if you make sure that myFunction returns a string with HTML


    This works?

    [snip]

    >
    > If you really want to set the frame content with script then it is safer
    > to have a function write to that frame e.g.
    > function initFrame () {
    > var frameDoc = window.frames.toc;
    > frameDoc.document.open();
    > frameDoc.document.write('html goes here');
    > frameDoc.document.close();
    > }
    >
    > <frameset onload="initFrame();" ...>
    > <frame src="fallback.html" name="toc">


    Well, yes, in contrast to what I said earlier, this is a way to do
    it--and now you're depending on both frames AND Javascript!
     
    Harlan Messinger, Jan 21, 2005
    #5
  6. Alex Molochnikov

    Toby Inkster Guest

    Alex Molochnikov wrote:

    > <frameset cols="50%,*">
    > <frame src=" ... HTML code for the frame ... ">
    > <frame src="Frame2.html" name="main">
    > </frameset><noframes></noframes>


    You could use a "data:" URL, but IIRC that's only supported by Gecko and
    Presto.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Jan 21, 2005
    #6
  7. "Harlan Messinger" <> wrote in message
    news:...
    > The purpose of frames (which is generally vastly outweighed by their
    > flaws and disadvantages) is to display content from multiple documents.
    > If you don't want to do that, why are you using frames at all? What is
    > meant to go in this "hidden" frame?


    This is an attempt to implement a browser callback to the servlet, mostly
    inspired by the Pushlets framework, as described in
    http://www.javaworld.com/jw-03-2000/jw-03-pushlet.html. The hidden frame
    would contain nothing, it would make a call on the servlet, and receive a
    Javascript code from it. The code, in its turn, can make requests on the
    servlet.

    This whole thing is needed to implement a Web-based frontend for interactive
    reports. The clear-view frame would initiate a request on the servlet to
    generate a report. Before the request is completed (i.e. before the doPost()
    or doGet() method returns), the servlet may have to get some additional info
    from the user (such as the customer number for the invoice). This cannot be
    done in the same frame without returning from the servlet's doGet/doPost
    methods. This is where the hidden frame comes in - it will receive the
    request from the servlet (a callback) to open another window with the
    necessary controls (text fields, buttons etc. depending on the nature of the
    additional info).

    The page that issues the report request is itself dynamically generated by
    the servlet. So I was trying to find a way to format it as a frameset with
    the frame content coming from the servlet, in a single requset-responce
    cycle (one-trip solution, if you wish). I know that the frame content in the
    frameset can be set to come from the servlet, instead of an html file, but
    this would require another trip to the servlet. So, I tried using the
    Javascript function; the function itself would be formatted by the servlet,
    with the necessary frame content.

    AM
     
    Alex Molochnikov, Jan 21, 2005
    #7
  8. "Martin Honnen" <> wrote in message
    news:41f14286$0$17602$-online.net...
    > If you really want to set the frame content with script then it is safer
    > to have a function write to that frame e.g.
    > function initFrame () {
    > var frameDoc = window.frames.toc;
    > frameDoc.document.open();
    > frameDoc.document.write('html goes here');
    > frameDoc.document.close();
    > }
    >
    > <frameset onload="initFrame();" ...>
    > <frame src="fallback.html" name="toc">


    Martin,

    Thank you for the response. I tried your solution, but it does not work.
    Here is my Frame.html that should display 2 frames:

    <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
    <html>
    <head>
    <title>Frame 1</title>
    <script type="text/javascript">
    function initFrame()
    {
    var frameDoc = window.frames.toc;
    frameDoc.document.open();
    frameDoc.document.write(
    "<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">
    <html>
    <head>
    <title>Frame 1</title>
    </head>
    <body>
    <H2>Frame 1</H2>
    </body>
    </html>"
    );
    frameDoc.document.close();
    }
    </script>
    </head>
    <frameset cols="50%,*">
    <frame onload=initFrame() src="" name="toc">
    <frame src="Frame2.html" name="main">
    </frameset>
    </html>

    The first frame (leftmost) comes out empty. Did I screw up the syntax? Any
    ideas?

    AM
     
    Alex Molochnikov, Jan 21, 2005
    #8
  9. "Toby Inkster" <> wrote in message
    news:p...
    > You could use a "data:" URL, but IIRC that's only supported by Gecko and
    > Presto.


    Then it won't work for me as I am targeting IE, NS and possibly Firefox as
    the primary browsers.

    AM
     
    Alex Molochnikov, Jan 21, 2005
    #9
  10. Alex Molochnikov wrote:

    > "Martin Honnen" <> wrote
    >>If you really want to set the frame content with script then it is safer
    >>to have a function write to that frame e.g.
    >> function initFrame () {
    >> var frameDoc = window.frames.toc;
    >> frameDoc.document.open();
    >> frameDoc.document.write('html goes here');
    >> frameDoc.document.close();
    >> }
    >>
    >> <frameset onload="initFrame();" ...>
    >> <frame src="fallback.html" name="toc">

    >


    > I tried your solution, but it does not work.


    Looks like you have changed what I posted, see below.

    > <!doctype html public "-//w3c//dtd html 4.0 transitional//en">


    If you want to use a DOCTYPE then use the frameset one in this case.

    > <html>
    > <head>
    > <title>Frame 1</title>
    > <script type="text/javascript">
    > function initFrame()
    > {
    > var frameDoc = window.frames.toc;
    > frameDoc.document.open();
    > frameDoc.document.write(
    > "<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">
    > <html>


    You need to put a JavaScript string literal on one line, if you want to
    have line breaks then use \r\n inside the string literal but what you
    have above should simply give a syntax error.


    > <frameset cols="50%,*">
    > <frame onload=initFrame() src="" name="toc">


    See above where I have put the onload.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 22, 2005
    #10
  11. Alex Molochnikov

    Jan Faerber Guest

    Jan Faerber, Jan 22, 2005
    #11
  12. ----- Original Message -----
    From: "Martin Honnen" <>
    Newsgroups: alt.html,comp.infosystems.www.authoring.html
    Sent: Saturday, January 22, 2005 7:00 AM
    Subject: Re: Embedded HTML in frameset - is it possible?
    > Looks like you have changed what I posted, see below.


    Yes, I did change it, but only after failing to get the code working in its
    original form.

    > You need to put a JavaScript string literal on one line, if you want to
    > have line breaks then use \r\n inside the string literal but what you
    > have above should simply give a syntax error.


    And that was it. My Java coding habits got in the way. After removing the
    line beaks, the code worked.

    Thank you very much.

    AM
     
    Alex Molochnikov, Jan 22, 2005
    #12
  13. Alex Molochnikov wrote:
    This is an attempt to implement a browser callback to the servlet, mostly
    > inspired by the Pushlets framework, as described in
    > http://www.javaworld.com/jw-03-2000/jw-03-pushlet.html. The hidden frame
    > would contain nothing, it would make a call on the servlet, and receive a
    > Javascript code from it. The code, in its turn, can make requests on the
    > servlet.
    >
    > This whole thing is needed to implement a Web-based frontend for interactive
    > reports. The clear-view frame would initiate a request on the servlet to
    > generate a report. Before the request is completed (i.e. before the doPost()
    > or doGet() method returns), the servlet may have to get some additional info
    > from the user (such as the customer number for the invoice). This cannot be
    > done in the same frame without returning from the servlet's doGet/doPost
    > methods.


    Right. You're *supposed* to return from the doGet or dPost method. You
    call the method whose purpose is to send the appropriate form to the
    user to get request the needed data--and then you return from doGet or
    doPost. When the user submits the form, it's submitted to a servlet (it
    may be the same servlet as the first one), calling the doPost method
    from scratch. It's not a continuation of the previous call. The method
    looks up the previous information from the transaction (in either
    session variables or session-related tables), incorporates the new data,
    and proceeds from there.

    What you're doing is an attempt to treat a web application as though it
    were a traditional application running on the client machine, consisting
    of a single routine that runs from beginning to end, successively
    displaying instructions and forms to the user to enter data, and
    continuing after the user finishes with each screen. This is an
    inefficient, problem-prone way to build web-based applications.

    > This is where the hidden frame comes in - it will receive the
    > request from the servlet (a callback) to open another window with the
    > necessary controls (text fields, buttons etc. depending on the nature of the
    > additional info).
    >
    > The page that issues the report request is itself dynamically generated by
    > the servlet.


    Naturally. That's what servlets do: generate pages dynamically. You say
    this as though it were a distinctive feature of your application.

    Surely you've seen plenty of e-commerce sites. None of them work the way
    you're trying to set up your application.

    [snip]
     
    Harlan Messinger, Jan 22, 2005
    #13
  14. "Harlan Messinger" <> wrote in message
    news:...
    > What you're doing is an attempt to treat a web application as though it
    > were a traditional application running on the client machine, consisting
    > of a single routine that runs from beginning to end, successively
    > displaying instructions and forms to the user to enter data, and
    > continuing after the user finishes with each screen. This is an
    > inefficient, problem-prone way to build web-based applications.


    This would be so, if the application in question _were_ a Web application.
    In reality it is not. This is a report generator that is a traditional
    3-tier client-server application that runs as a Swing-based client, and as a
    headless server (not servlet) process, and displays the reports in a
    Java-generated window (JFrame). And, depending on the design of a particular
    report, it _may_ communicate with the user via the server-side callbacks.

    Publishing the generated report over the Web is a small appendix to the
    entire design, an add-on option. And it must fit into the existing design
    structure, which can start the report process in one thread, and then,
    before the report finishes, get back to the user in a different thread, get
    some additional input, and carry on until the report is done, or until
    another callback comes, with more info requests. It is this interactive part
    of the functionality that is currently missing from the Web-published
    reports, and I am trying to find a way to implement it through a combination
    of Javascript, servlet-side callbacks, frames, possibly pop-ups and whatever
    else I can think of. The availability of Javascripts, the need to enable
    cookies, and any other requirement is not a concern.

    > Naturally. That's what servlets do: generate pages dynamically. You say
    > this as though it were a distinctive feature of your application.


    The reason I mention it is the need to incorporate the Javascript into that
    dynamically generated content, and the difficulties I had (still have)
    getting this Javascript code called upon loading the frame, and connecting
    back to the servlet.

    > Surely you've seen plenty of e-commerce sites. None of them work the way
    > you're trying to set up your application.


    They are all based on the complete request-return cycle, with no servlet
    callbacks cutting in-between. As explained above, the application in
    question does not work this way. In short, it is not a Web application in
    the customary sense. I really do not want to come across as trying to turn
    this post into a commercial, promoting our product, but if you a curious,
    you can have a look at www.reportgenerator.org to see how this thing is
    organized.

    Regards,

    Alex.
     
    Alex Molochnikov, Jan 23, 2005
    #14
  15. Alex Molochnikov

    Jim Michaels Guest

    "Alex Molochnikov" <> wrote in message
    news:lTaId.136774$6l.113213@pd7tw2no...
    > Is there any way to embed the HTML code inside FRAMESET? Something like
    > this:
    >
    > <frameset cols="50%,*">
    > <frame src=" ... HTML code for the frame ... ">
    > <frame src="Frame2.html" name="main">
    > </frameset><noframes></noframes>
    >
    > I tried using a Javascript function that returns the HTML text, as in the
    > following code:
    >
    > <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
    > <html>
    > <head> <title>Frame 1</title>
    > <script type="text/javascript">
    > function myFunction()
    > {
    > return ("<!doctype html public \"-//w3c//dtd html 4.0
    > transitional//en\">
    > <html>
    > <head>
    > <title>Frame 1</title>
    > </head>
    > <body>
    > <H2>Frame 1</H2>
    > </body>
    > </html>
    > ")
    > }
    > </script>
    > </head>
    > <frameset cols="50%,*">
    > <frame src=myFunction() name="toc">



    try javascript:myFunction() instead and see what happens.

    > <frame src="Frame2.html" name="main">
    > </frameset><noframes></noframes>
    > </html>
    >
    > but the browser shows the "The page cannot be displayed" for the first
    > frame.
    >
    > I am trying to find a way to generate a page from the Java servlet that
    > would contain a hidden (0-width) frame and a fully visible frame with some
    > dynamic content.
    >
    > I will appreciate any clues.
    >
    > Alex Molochnikov
    >
    >
     
    Jim Michaels, Feb 4, 2006
    #15
  16. Alex Molochnikov

    Jim Michaels Guest

    "Alex Molochnikov" <> wrote in message
    news:lTaId.136774$6l.113213@pd7tw2no...
    > Is there any way to embed the HTML code inside FRAMESET? Something like
    > this:
    >
    > <frameset cols="50%,*">
    > <frame src=" ... HTML code for the frame ... ">
    > <frame src="Frame2.html" name="main">
    > </frameset><noframes></noframes>
    >
    > I tried using a Javascript function that returns the HTML text, as in the
    > following code:
    >
    > <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
    > <html>
    > <head> <title>Frame 1</title>
    > <script type="text/javascript">
    > function myFunction()
    > {
    > return ("<!doctype html public \"-//w3c//dtd html 4.0
    > transitional//en\">
    > <html>
    > <head>
    > <title>Frame 1</title>
    > </head>
    > <body>
    > <H2>Frame 1</H2>
    > </body>
    > </html>
    > ")
    > }
    > </script>
    > </head>
    > <frameset cols="50%,*">
    > <frame src=myFunction() name="toc">


    <frame src="javascript:'<html></html>'">
    is valid (tinker with it).
    you can also try
    function myFunction() {
    window.frames[0].document.write(
    "<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">
    <html>
    <head>
    <title>Frame 1</title>
    </head>
    <body>
    <H2>Frame 1</H2>
    </body>
    </html>
    ");
    }



    > <frame src="Frame2.html" name="main">
    > </frameset><noframes></noframes>
    > </html>
    >
    > but the browser shows the "The page cannot be displayed" for the first
    > frame.
    >
    > I am trying to find a way to generate a page from the Java servlet that
    > would contain a hidden (0-width) frame and a fully visible frame with some
    > dynamic content.
    >
    > I will appreciate any clues.
    >
    > Alex Molochnikov
    >
    >
     
    Jim Michaels, Feb 4, 2006
    #16
    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. Replies:
    0
    Views:
    673
  2. xzzy
    Replies:
    4
    Views:
    641
  3. ck388
    Replies:
    1
    Views:
    574
    ck388
    Sep 24, 2003
  4. Julius Mong
    Replies:
    1
    Views:
    380
    Randy Webb
    May 10, 2004
  5. Stefan Mueller
    Replies:
    0
    Views:
    228
    Stefan Mueller
    Nov 7, 2005
Loading...

Share This Page