By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,238 Members | 1,659 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,238 IT Pros & Developers. It's quick & easy.

document.write

P: 7
Hi,
I want to use document.write() in stead of innerhtml. But everything is getting cleared, while writing new content.
I am losing registered callbacks on that object like onclick etc.
But I want to preserve the previous things.
Is this possible?
Oct 12 '07 #1
Share this Question
Share on Google+
12 Replies


dmjpro
100+
P: 2,476
Hi,
I want to use document.write() in stead of innerhtml. But everything is getting cleared, while writing new content.
I am losing registered callbacks on that object like onclick etc.
But I want to preserve the previous things.
Is this possible?
try...........

Expand|Select|Wrap|Line Numbers
  1. document.write(document.body.innerHTML+"your content goes here");
  2.  
Debasis Jana
Oct 12 '07 #2

P: 7
Nope :(
It does not work.
I want to clear previous content, but not the registered onclick functions.
This preserved my prev content, but still I lost onclick.
Oct 12 '07 #3

dmjpro
100+
P: 2,476
Nope :(
It does not work.
I want to clear previous content, but not the registered onclick functions.
This preserved my prev content, but still I lost onclick.
On which Control you lost Registered "OnClick"?
Post the related code here.
And tell the problem elaborately.

Debasis Jana.
Oct 12 '07 #4

P: 7
I have code something like this -

document.onclick = func;
document.ondblclick = func;
document.onkeyup = func;
etc.

Now when I write

document.body.innerHTML = html;

When I click on the component, the 'func' gets called.

But when my code is

document.open();
document.write(html);
document.close();

The 'func' is never called.
Oct 12 '07 #5

dmjpro
100+
P: 2,476
I have code something like this -

document.onclick = func;
document.ondblclick = func;
document.onkeyup = func;
etc.

Now when I write

document.body.innerHTML = html;

When I click on the component, the 'func' gets called.

But when my code is

document.open();
document.write(html);
document.close();

The 'func' is never called.
Use code tags....

You better to have it....
Expand|Select|Wrap|Line Numbers
  1. window.onclick = func;
  2. window.ondblclick = func;
  3. window.onkeyup = func;
  4.  
Debasis Jana
Oct 12 '07 #6

P: 7
This is just extract of the code what I have.
Actually I can not change that to window.onclick.I am not allowed to touch that code.
Whatever I have to handle is while writing the content. :(
Previously I was using innerhtml only, but for some issues I need to change it to document.write
Oct 12 '07 #7

dmjpro
100+
P: 2,476
This is just extract of the code what I have.
Actually I can not change that to window.onclick.I am not allowed to touch that code.
Whatever I have to handle is while writing the content. :(
Previously I was using innerhtml only, but for some issues I need to change it to document.write
Well let me know ... what do you want to update?
You want to clear the previous Screen but still want to have event registration.
Right?

Debasisi Jana
Oct 12 '07 #8

P: 7
Yes.
exactly :)
I just want to replace the content without disturbing anything else.
Oct 12 '07 #9

dmjpro
100+
P: 2,476
Yes.
exactly :)
I just want to replace the content without disturbing anything else.
have a try this ..............

Expand|Select|Wrap|Line Numbers
  1. var child_s = document.body.childNodes;;
  2. var i=0;
  3. for(;i<child_s.length;){
  4.  document.body.removeChild(child_s[i]);
  5.  child_s = document.body.childNodes;
  6.  i=0;
  7. }
  8. document.body.innerHTML = "your_html_content";
  9.  
Good Luck !

Debasis Jana
Oct 12 '07 #10

P: 7
I can not use innerhtml, bcoz innerhtml gives me problems when I have corrupted html. To overcome corrupted html content, I want to use document.write.
Otherwise in case of innerhtml, all my registrations are preserved.

I am losing the registraions when I do document.write
Oct 12 '07 #11

dmjpro
100+
P: 2,476
I can not use innerhtml, bcoz innerhtml gives me problems when I have corrupted html. To overcome corrupted html content, I want to use document.write.
Otherwise in case of innerhtml, all my registrations are preserved.

I am losing the registraions when I do document.write
Again you can not do registration, after use "document.write".

Debasis Jana
Oct 12 '07 #12

acoder
Expert Mod 15k+
P: 16,027
I can not use innerhtml, bcoz innerhtml gives me problems when I have corrupted html. To overcome corrupted html content, I want to use document.write.
Otherwise in case of innerhtml, all my registrations are preserved.

I am losing the registraions when I do document.write
You cannot use document.write after the page has loaded. If innerHTML is giving you problems because of corrupted HTML, that's a good thing. Fix the corrupted HTML first.
Oct 15 '07 #13

Post your reply

Sign in to post your reply or Sign up for a free account.