...

View Full Version : Need document.write() to fire event, how?



oivind
06-05-2006, 03:28 PM
I have been searching for a way to trap changes done to the document object (mainly by the function document.write();).

Example of code that doesn't work:

function myFunction() {
ed.document.onchange = doFunction(document.body.innerHTML);
ed.document.open();
ed.document.write('Hello');
ed.document.close();
}

function do_function(body) {
alert(body);
}

It only fires when the page loads, not when I change the text. You are free to use any event that works, but i think onchange was the one to fit this problem. The alert will write the initialpage, but will never write the tekst 'Hello' that is the new change.

Any javagurus out there know a solution to pick up any fired events triggered by document.write();

Kor
06-05-2006, 03:32 PM
The logical answer for me is that you should simply fire the function whithin the function which writes

function myFunction() {
ed.document.open();
ed.document.write('Hello');
ed.document.close();
doFunction(document.body.innerHTML);
}

oivind
06-05-2006, 03:35 PM
Well, my javascript need to gain control over what other javascripts try to change on the page. I have no access to the other scripts, therefore i need to pick up event fired by write() to do some checks.

Vladdy
06-05-2006, 06:44 PM
Javasripts are TEXT files that reside on YOUR server. Surely you have access to them....

Beagle
06-05-2006, 08:43 PM
well, no, Vladdy...you can easily import scripts from other servers.

I don't know about any events that are triggered by document.write(). There is no commonly known event that is dispatched when document.write completes. There may not be one at at all, but try document.onreadystatechange. That's the best I got, sorry.

oivind
06-05-2006, 09:43 PM
Vladdy, why is everyone so interested in alternative solutions ? my question is what it is, and i need å solution.. very simple...

It's a CMS that is under development and users will be able to evaluate the product before buy, these users will have an ugly textbox on the screen that says that this is an evaluation versjon. CMS users should be able to add their own javascript, but these scripts should not remove the textbox. So again, the javascripts are not on my server, I'm making the script, but it will be distributed with the CMS. Do you get it ?

Beagle, thank you for your tips, but onreadystatechange doesn't do what i want either :(

If anyone knows any solution how to ensure that the textbox is not removed, please tell me :)

Beagle
06-05-2006, 09:57 PM
If they can put they're own scripts in you're completely boned, there isn't anything you can do that they can't reverse.

You can make it interesting for them, by having various things test for the existence of the textarea, and if it's not there recreate it, but ultimately, there really is nothing you can do. By giving your users the ability to code their own arbitrary scripts, you put them on equal footing with you, and they can kick you as hard as you can kick them.

It's better to not allow scripts at all or require them to be audited first.

Sorry.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum