|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
innerHTML question
I recently read the "Building a WYSIWYG" article and thought it was GREAT!
However, I am stuck with one question that I cannot find an answer to. Using the wysiwyg to create content is fine and easy, however, what if I want to pull the saved content from the database and re-populate the WYSIWYG so I can update the content? Specifically, I have been unable to populate the Iframe's innerHTML with the HTML that was saved in the database. Any help is appreciated! Brant |
|
#2
|
|||
|
|||
|
can't you just do something like this
<script> function populate() { object.innerHTML = <%= rs.getString(2)%> } </script> if you don't understand this then post back and I'll explain, I've tried too explain it, but maybe you'll just get it? It may help if you say what language you are using. that is the JSP way of doing it. |
|
#3
|
|||
|
|||
|
Right, but...
I guess I didn't explain well enough.
You are right with your explanation, thank you. I can get that to work.. no problem. My problem is when the page loads, I cannot make an "onLoad" that can take the content I am providing and prepopulate the iFrame. Here is the function I created (Cold Fusion, BTW): Code:
function addContent() {
var contents = "#attributes.content#";
iView.document.body.innerHTML = contents;
}
(iView is the name of the iFrame) If I make a button that has onClick=addContent(), it works great. However, I need an onload=addContent() that will populate the iframe when the page loads. When I do this, I get the following error: Code:
'iView.document.body' is null or not an object. Any ideas? |
|
#4
|
|||
|
|||
|
try this
Code:
<script>
var iViewContentLoaded = false;
function addContent() {
// Check to see if content has been loaded
if(!iViewContentLoaded) {
// Check to see if there is an iView.document.body object
if(iView.document.body) {
// The object exists so populate it
var contents = "#attributes.content#";
iView.document.body.innerHTML = contents;
iViewContentLoaded = true;
} else {
// The object doesn't exist yet, so we'll try again in 2 seconds
setTimeout("addContent()", 2000);
}
}
}
</script>
Because you said it works when you click a button, it seems that onLoad, is doing its thing before the iFrame has been created. This code is self explainetory, but if you need clarification then ask. |
|
#5
|
|||
|
|||
|
That worked!
Thanks so much for all your help! That worked perfectly!
![]() |
|
#6
|
|||
|
|||
|
"One is always glad to be of service"
|
|
#7
|
|||
|
|||
|
ONE more question...
Ok, now I understand how to use the innerHTML, outerHTML features. Now I am wondering this...
I made a colorpicker that allows the user to change the background color of the entire iframe. It works ok, when the user saves the content, it saves the <body bgcolor="#ffcc00"> tag as part of the content. I used the outerHTML to do this. This works good. Now, I want to pull this content out of the database, and put the content back in the iframe for editing.... which you showed me how to do. In fact, it works perfectly EXCEPT... the background color <body> defaults to white in the iframe, even though the body tag says it is another color. HOW do I pull the color out of the body tag and use it to change the background of the iframe? Thanks for the help! |
|
#8
|
|||
|
|||
|
I've had a go at this but I can't figure it out. sorry.
But with the code above: I was using the code above and noticed a flaw in my logic, if you step through the code abpve you'll realise I test to see if the object is loaded twice (indirectly) but it is overhead that isn't needed so to fix it use this Code:
<script>
function addContent() {
// Check to see if there is an iView.document.body object
if(iView.document.body) {
// The object exists so populate it
var contents = "#attributes.content#";
iView.document.body.innerHTML = contents;
} else {
// The object doesn't exist yet, so we'll try again in 2 seconds
setTimeout("addContent()", 2000);
}
}
</script>
|
|
#9
|
|||
|
|||
|
innerHTML with onload and timeout
Having the same problem I tried this sollution, however I keep getting an error when the function fires for the second time.
var iViewContentLoaded = false; function populate() { if(!iViewContentLoaded) { if(iView.document.body) { // The object exists so populate it var contents = 'some stuff'; iView.document.body.innerHTML = contents; iViewContentLoaded = true; } else { // The object doesn't exist yet, so we'll try again in 2 seconds setTimeout("addContent()", 2000); } } } With onload the time out is triggered and the page reads done. After two seconds it reads error on page: Error: Object expected I tried putting a prompt in there, and if the prompt is situated before the if loop, as in, prompt, then execute if statement the function works, but without the promt, even with the timeout function the error keeps occuring... ANY ONE help? |
|
#10
|
|||
|
|||
|
/me thinks you need to call "popuate()" again before you go onto "addContent()"
![]() |
|
#11
|
|||
|
|||
|
Oh my!
That did it! Will teach me to rename my functions ![]() |
|
#12
|
|||
|
|||
|
WYSIWYG and populate data from DB
hi Nigor
having some truble with my code maybe u kan help (or someone else) can populate data from DB in iframe (almoste). the problem is that some DB data dont show in ifram (like bullit) but underline works ??? can someone help ??? //aid |
|
#13
|
||||
|
||||
|
how does this relate to this thread?
perhaps you could achieve better results if you created a new thread for your question Last edited by MadCowDzz : February 24th, 2004 at 08:48 PM. Reason: I see you did... ignore this post =) |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Programming Tools > innerHTML question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|