Setting innerHTML

  • Thread starter Chris Moltisanti
  • Start date
C

Chris Moltisanti

Hey,

I have a DIV and I want to dynamically set its innerHTML. I know I can
set it by doing the following myDiv.innerHTML = '<img
src=\"myImage.gif\">'
However, the html that I want to set in it is quite large so I dont
want to have to hard code the HTML like I just did.
My question is....is it possible to assign an existing html page to the
innerHTML.
e.g. myDiv.innerHTML = 'mytest.html'
So that the contents of the mytest.html would be set in myDiv's
innerHTML.

Thanks,

Chris
 
C

Chris Moltisanti

Thanks for the reply.

I have use AJAX a little bit, bu I am unfamiliar with calling a pag
with AJAX. Any ideas on the syntax to do this?
I thought AJAX was more for making server calls.......

Chris.
 
E

Evertjan.

Chris Moltisanti wrote on 06 jun 2006 in comp.lang.javascript:
Thanks for the reply.

What reply?

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at the
top of the article, then click on the "Reply" at the bottom of the article
headers.

<http://www.safalra.com/special/googlegroupsreply/>
 
C

Chris Moltisanti

The previous post is not related to javascript so please ignore it.
My question again is how can I get an animated GIF to continue
animating while some javascript processing is bien executed.

Thanks

Chris
 
C

Chris Moltisanti

The previous post is an annoyance and unrelated to javascript. Please
ignore it.
My question again........how do I call a page using AJAX? Is AJAX not
ususally used for server calls?

Thanks

Chris
 
I

Ivo

The previous post is an annoyance and unrelated to javascript. Please
ignore it.
My question again........how do I call a page using AJAX? Is AJAX not
ususally used for server calls?

What previous post? You didn't quote it, which is a very simple thing to do,
which is one of the reasons why quoting previous posts has become such a
common thing on Usenet. The other reason is of course that it is nothing but
sensible to quote what you are replying to. I 'd like to be able to judge
for myself whether or not it is related to javascript, not because I don't
trust your judgement, but just because I 'd like to help take the discussion
further. And how can I discuss what I haven't read?

As to the thoughts on AJAX: I believe if I make an AJAX call, it is by
definition to a server. If the URL used is (also) meant to be accessed
through a regular HTTP connection and viewed in a browser on its own, you
might indeed say I am calling "a page" using AJAX, but the word game has
little significance. Whatever the server responds with is either a string of
text (possibly containing HTML tags or other code) or an XML object to the
receiving javascript, and is to be treated as such within the original page.

hth
ivo
http://www.yorick.onlyfools.com/
 
E

Eric Ryan Harrison

Another more simplistic option would be to have your javascript merely
use document.createElement to create an iframe, set the iframes src to
whatever page you want the div to contain and then appendChild on the
div. Maybe not as clever or web2.0'ish enough for you, but it
definitely will get the job done in the least amount of code.

-E

andy said:
Thanks for the reply.

I have use AJAX a little bit, bu I am unfamiliar with calling a pag
with AJAX. Any ideas on the syntax to do this?
I thought AJAX was more for making server calls.......

I've just been doing something like this using dojo (www.dojotoolkit.org),
which makes it pretty easy:

function infoPage(url,callback) {
// the url to load.
this.url=url;
// is the file loaded and parsed?
this.ready= false;
// did the loading fail?
this.fail=false;
// reference to a div with the page in it.
this.infoNode=null;
// callback for when the html has loaded.
this.callback=callback;
this.load= function() {
// load the data file.
var bindArgs = {
url: this.url,
mimetype: "text/html",
error: dojo.lang.hitch(this,"loadError"),
load: dojo.lang.hitch(this,"loaded")
};
var requestObj = dojo.io.bind(bindArgs);
};
this.loaded=function(type, data, evt){
// handle successful response here
// parse HTML into DOM nodes.
var newNodes=dojo.html.createNodesFromText(data,true);
this.infoNode=newNodes[0];
// callback which does any further processing - e.g. inserting the node
in the document.
this.ready=true;
this.callback(this);
};
this.loadError= function(type, errObj){
// handle error here
this.fail=true;
alert("Failed to load page");
}
}

If you don't like toolkits, you'll probably have to write your own
javascript to parse html into DOM nodes, or else use innerHTML.
 
E

Eric Ryan Harrison

andy said:
I tried this way first, but I didn't like the iframe - you have to set a
fixed height window with a scrollbar and it looked ugly in my layout.

I don't know exactly what you're reffering to here. I've seen some
darned pretty Iframes. Iframes are CSS-ready, and if the page coming
back in the iframe has any sort of style, it'll be properly rendered as
well.

Good luck,

-E
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Thu, 8 Jun
2006 11:07:03 remote, seen in Tony <tony23@ds
lextreme.WHATISTHIS.com> posted :
Why are you telling me what to do?

What post are you referring to?

Please quote what you are replying to. If you don't want to play by the
rules, then go play somewhere else.

He's a Google user, so don't assume intelligence; tell him to read the
newsgroup FAQ.
 
L

lofty00

Eric said:
I don't know exactly what you're reffering to here. I've seen some
darned pretty Iframes. Iframes are CSS-ready, and if the page coming
back in the iframe has any sort of style, it'll be properly rendered as
well.

Good luck,

As far as I know, an iframe has to have a fixed height and any overflow
is dealt with by putting a scrollbar in the window. I didn't want that
- I just wanted the html included in the page like any other html text.

andy baxter (lofty00 while I'm away)
 
E

Eric Ryan Harrison

As far as I know, an iframe has to have a fixed height and any overflow
is dealt with by putting a scrollbar in the window. I didn't want that
- I just wanted the html included in the page like any other html text.

Huh? I personally don't know what your source is for this. It may be
that this is true and I've just been using browsers that don't have
this behavior. I use IFrames in a few different places and have seen
this working on IE6, FF 1.0-1.5, Netscape 7, and Mozilla 1.6.

<h2>Default (Non-Pretty) Iframe</h2>
<iframe name="nonpretty" id="nonpretty"
src="javascript:void(0);"> </iframe>

<hr />

<h2>CSS Styled (Pretty) Iframe</h2>

<iframe name="pretty" id="pretty" src="javascript:void(0);"
style="background-color:#fca;height:300px;width:600px;overflow:auto;border:1px
dashed #777;"> </iframe>

( I always add the   so that XML doesn't gak up on <iframe>
auto-closing the empty element when I do ajax stuff. &nbsp; isn't
recognized as a valid XML entity, so I use   which works like a
charm. )

Take a look. Should see beautiful iframes. Let me know if anything
crazy happens.

-E
 
R

Randy Webb

Dr John Stockton said the following on 6/9/2006 12:23 PM:
JRS: In article <[email protected]>, dated Thu, 8 Jun
2006 11:07:03 remote, seen in Tony <tony23@ds
lextreme.WHATISTHIS.com> posted :

He's a Google user, so don't assume intelligence;

Being a "Google user" applies to many more people that what you thought
you intended to say. "Google Group user" isn't any better though. The
user of an interface is as much a reflection of intelligence as the
color of the sun - it isn't and it's irrelevant.

The only time you see problems with Google Groups is when a new person
is using it. You don't pay attention to the people who use it without
problems because you only pay attention to where they post from if there
is a problem in quoting.
tell him to read the newsgroup FAQ.

And nothing in that FAQ deals specifically with how to quote using
Google Groups so pointing a user to that FAQ doesn't help the problem
any at all.

A better reference would be somewhere that deals with that particular
piece of software. It is no different than pointing an un-patched OE
user to an OE-fix page, or do you point them to the FAQ as well in a
round of futility?
 
L

lofty00

Eric said:
Huh? I personally don't know what your source is for this. It may be
that this is true and I've just been using browsers that don't have
this behavior. I use IFrames in a few different places and have seen
this working on IE6, FF 1.0-1.5, Netscape 7, and Mozilla 1.6.

<h2>Default (Non-Pretty) Iframe</h2>
<iframe name="nonpretty" id="nonpretty"
src="javascript:void(0);"> </iframe>

<hr />

<h2>CSS Styled (Pretty) Iframe</h2>

<iframe name="pretty" id="pretty" src="javascript:void(0);"
style="background-color:#fca;height:300px;width:600px;overflow:auto;border:1px
dashed #777;"> </iframe>

( I always add the   so that XML doesn't gak up on <iframe>
auto-closing the empty element when I do ajax stuff. &nbsp; isn't
recognized as a valid XML entity, so I use   which works like a
charm. )

Take a look. Should see beautiful iframes. Let me know if anything
crazy happens.

I does look better that way, but if I include a document in the iframe
that's longer than the height of the frame, it makes a scrollbar on the
right hand side to deal with the overflow. This isn't what I want - I
want it to expand to the full length of the included document, with any
scrolling being through the scrollbar on the main window. I don't think
there's a way to do this with iframes.

andy
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated
Sat, 10 Jun 2006 13:14:55 remote, seen in
Randy Webb said:
And nothing in that FAQ deals specifically with how to quote using
Google Groups so pointing a user to that FAQ doesn't help the problem
any at all.

You should read the newsgroup FAQ.

comp.lang.javascript FAQ - 8.1 - 2005-11-05
Section 2.3, paragraph 7, which cites paragraph 6, refers.

(6) When replying to a message on the group quote the minimum of the
preceding messages post that is sufficient to provide context for the
reply but trim the remainder, and add your comments below the pertinent
section of quoted material, as per FYI28/RFC1855 (never top post).

(7) If posting through groups.google.com don't use the "Reply" link at
the bottom of the article, instead use "Show Options" at the top of the
article and than click the "Reply" option exposed there. This
automatically includes the quote of the preceding message to be edited
down as described above.


I leave the following in HTML for the convenience of those who might
wish to put something similar on their sites :-

<p>Also see <a
href="http://groups.google.com/support/bin/answer.py?answer=14213">How
can I automatically quote the previous message when I post a reply?</a>
in Google Groups Help.</p>


<FAQENTRY> In the first line of 2.3 para 6, suggest inserting ", with
'>', " in the first line.
 
R

Randy Webb

Dr John Stockton said the following on 6/10/2006 5:42 PM:
JRS: In article <[email protected]>, dated
Sat, 10 Jun 2006 13:14:55 remote, seen in

You should read the newsgroup FAQ.

comp.lang.javascript FAQ - 8.1 - 2005-11-05
Section 2.3, paragraph 7, which cites paragraph 6, refers.

I did, and the version at <URL: http://jibbering.com/faq/> that I get is :

comp.lang.javascript FAQ - 8.0 - 2004-03-15

Which is obviously wrong but it is the same version that anybody else
would get unless a URL to a post of it in the archives is given instead.
I got tired of messing with Google Groups to try to find a URL to the
last FAQ Poster posted FAQ article. Does anybody have one?
 
E

Eric Ryan Harrison

I does look better that way, but if I include a document in the iframe
that's longer than the height of the frame, it makes a scrollbar on the
right hand side to deal with the overflow. This isn't what I want - I
want it to expand to the full length of the included document, with any
scrolling being through the scrollbar on the main window. I don't think
there's a way to do this with iframes.

Have you tried this: ( note: I haven't tested this, so if it doesn't
work, let me know )

<iframe name="pretty" id="pretty" src="http://google.com"
style="background-color:#fca;height:300px;width:600px;overflow:visible;border:1px
dashed #777;"> </iframe>

CSS's overflow:visible property is supposed to do just that. Anything
bigger than your defined size will cause the element to expand to show
the containing data.

Give this a try.

-E
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated
Sat, 10 Jun 2006 19:04:53 remote, seen in
Randy Webb said:
Dr John Stockton said the following on 6/10/2006 5:42 PM:

I did, and the version at <URL: http://jibbering.com/faq/> that I get is :

comp.lang.javascript FAQ - 8.0 - 2004-03-15

Which is obviously wrong but it is the same version that anybody else
would get unless a URL to a post of it in the archives is given instead.
I got tired of messing with Google Groups to try to find a URL to the
last FAQ Poster posted FAQ article. Does anybody have one?

You can see the HTML version, less CSS, HTML *possibly* edited a bit, at
<URL:http://www.merlyn.demon.co.uk/$clj-faq.htm> but I don't intend to
keep a version there for more than a day or so. It's a copy of what I
saved for reference.

I would not have kept the last posted version; alas, I omitted to keep
the first posted one in my newsbase - it would have had a message-ID.
Its header should have included one of
Subject: comp.lang.javascript FAQ - Quick Answers- 8.1 - 2005-11-05
Subject: comp.lang.javascript FAQ - Quick Answers - 8.1 - 2005-11-05
which may help finding it.

A search for part of the paragraph of my previous article :-
<If posting through groups.google.com don't use the "Reply" link at
the bottom of the article, instead use "Show Options" at the top of the
article and than click the "Reply" option exposed there. This
automatically includes the quote of the preceding message to be edited
down as described above.>
might work.
 
R

Randy Webb

Dr John Stockton said the following on 6/11/2006 3:02 PM:
JRS: In article <[email protected]>, dated
Sat, 10 Jun 2006 19:04:53 remote, seen in

You can see the HTML version, less CSS, HTML *possibly* edited a bit, at
<URL:http://www.merlyn.demon.co.uk/$clj-faq.htm> but I don't intend to
keep a version there for more than a day or so. It's a copy of what I
saved for reference.

I would not have kept the last posted version; alas, I omitted to keep
the first posted one in my newsbase - it would have had a message-ID.
Its header should have included one of
Subject: comp.lang.javascript FAQ - Quick Answers- 8.1 - 2005-11-05
Subject: comp.lang.javascript FAQ - Quick Answers - 8.1 - 2005-11-05
which may help finding it.

<URL:
http://groups.google.com/group/comp...rs+-+8.1+-+2005-11-05&rnum=1#e3f59d54ce1e2a9f>

Yikes what a URL, but that is the newest one Google finds for it.
That is not the HTML version but it's better than the version found on
jibbering for me right now.

I put your HTML version - along with the CSS file - here:

<URL: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/>
 
M

Matt Kruse

Dr said:
JRS: In article <[email protected]>, dated
Sat, 10 Jun 2006 13:14:55 remote, seen in
You should read the newsgroup FAQ.

As an alternative to the long and overwhelming newsgroup FAQ, I created the
"Newbie FAQ":
http://www.javascripttoolbox.com/clj/

This is my attempt to provide useful information (including a link to the
newsgroup FAQ) to newbie users who often make posting mistakes or aren't
familiar with the group.

For example, if someone replies incorrectly with google groups you can
simply direct them to:
http://www.javascripttoolbox.com/clj/#howtoreply

Or if someone posts a question and doesn't provide enough useful information
or a minimal test case, you can point them to:
http://www.javascripttoolbox.com/clj/#getanswers

etc. I'm not sure if people will find it useful or use it, but it exists :)
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top