Embedded HTML in frameset - is it possible?

A

Alex Molochnikov

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
 
B

Ben Measures

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

Alex said:
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
 
M

Martin Honnen

Alex said:
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">
 
H

Harlan Messinger

Alex said:
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?
 
H

Harlan Messinger

Martin said:
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!
 
T

Toby Inkster

Alex said:
<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.
 
A

Alex Molochnikov

Harlan Messinger said:
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
 
A

Alex Molochnikov

Martin Honnen said:
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
 
A

Alex Molochnikov

Toby Inkster said:
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
 
M

Martin Honnen

Alex said:
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.
 
A

Alex Molochnikov

----- Original Message -----
From: "Martin Honnen" <[email protected]>
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
 
H

Harlan Messinger

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]
 
A

Alex Molochnikov

Harlan Messinger said:
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.
 
J

Jim Michaels

Alex Molochnikov said:
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.
 
J

Jim Michaels

Alex Molochnikov said:
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>
");
}
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top