Attaching SSI with Javascript. Small syntax problem..

P

Paul

HI! I am trying to dynamically add content into Div tags with the use of
JavaScript. it loads the page but adds a few characters. the script is
below.

<script language="JavaScript">
document.write('<div id=DivExample>"<!--#include
virtual="/Include_Pages_Asp/Main.htm" --></div>');
</script>

The characters that are added is right after the end of Main.htm page. they
are as follows.

');

I also get this JavaScript error in IE

Line: 48
Char:106
Error:Unterminated string constant.

Since the page does load fully I suspect that Its a small syntax problem but
I just don't know what.

can someone tell me what I am doing wrong?
 
S

Stefan B Rusynko

Your JS error is from mismatched quotes (extra " after <div id=DivExample>" )
Use
<script language="JavaScript">
document.write('<div id=DivExample><!--#include virtual="/Include_Pages_Asp/Main.htm"--></div>');
</script>




| HI! I am trying to dynamically add content into Div tags with the use of
| JavaScript. it loads the page but adds a few characters. the script is
| below.
|
| <script language="JavaScript">
| document.write('<div id=DivExample>"<!--#include
| virtual="/Include_Pages_Asp/Main.htm" --></div>');
| </script>
|
| The characters that are added is right after the end of Main.htm page. they
| are as follows.
|
| ');
|
| I also get this JavaScript error in IE
|
| Line: 48
| Char:106
| Error:Unterminated string constant.
|
| Since the page does load fully I suspect that Its a small syntax problem but
| I just don't know what.
|
| can someone tell me what I am doing wrong?
|
| --
| Thanks in advance :)
|
| Paul
|
|
|
 
J

Jon Spivey

That's not going to work though. Includes need to happen on the server, this
include directive is being written out on the client by which time it's too
late to include.

Without knowing exactly what this chap has in mind I'd suggest including the
page and then using javascript to display it if needed.
 
M

Martin Walke

Hi Paul,

Interestingly it's actually the first single quote, .write('<div, that the
browser thinks is unmatched.

If I understand you correctly, you want to include one HTML file inside
another, which I don't think you can do directly. We do something similar by
loading the include file into a hidden frame, then read the HTML out into a
variable and re-assign it to the innerHTML of your div.

HTH
Martin
 
B

Bob Barrows [MVP]

Actually, it looks like you should be using an iframe instead of a div. That
will allow you to:

<script language="JavaScript">
document.write('<iframe id=ifExample
src="/Include_Pages_Asp/Main.htm"></iframe>');
</script>

Or, better yet:

<script language="JavaScript">
var obj = document.createElement("iframe");
obj.src="/Include_Pages_Asp/Main.htm";
document.body.appendChild(obj);
</script>
 
P

Paul

HI! thanks for the reply. For the first question if I am tying to put an
page inside another the answer is Yes.
The reason that I am trying this method is because the child page ( or the
include page) will have another Iframe as well. and I want to have the first
child auto fit its content. into the page main page.

The problem that I ran into with iframes on the main page before was it
resized with another script that I used but in Firefox browser there appears
to be a bug with the CSS height attribute "Auto" for the body tag.

Perhaps I will try what you suggested anyways since its different than my
other approach using iframe.

I would prefer not using a iframe for the main child page.

Paul
 
B

Bob Barrows [MVP]

In order for this approach (using a dynamic div) to have a chance, you have
to make a couple changes to your SSI file:

1. remove the html, head and body tags, so that all that is left is the
2. remove all the line breaks and, optionally, the whitespace

<script language="JavaScript">
//the following must be on a single line:
document.write('<div id=DivExample><!--#include
virtual="/Include_Pages_Asp/Main.htm" --></div>');
</script>

or, better yet:
<script language="JavaScript">
var obj=document.createElement("div");
obj.id="DivExample"
div.innerHTML='<!--#include virtual="/Include_Pages_Asp/Main.htm" -->';
document.body.appendChild(obj);
</script>

Important: ALL line breaks must be removed from Main.htm

Bob Barrows
 
B

Bob Barrows [MVP]

Bob said:
In order for this approach (using a dynamic div) to have a chance,
you have to make a couple changes to your SSI file:

1. remove the html, head and body tags, so that all that is left is
the
html for the table.
 
P

Paul

Thanks bob, I will give it a shot :)

Paul


Bob Barrows said:
html for the table.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
 

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

Top