Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need document.write() to fire event, how?

    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();

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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);
    }
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Javasripts are TEXT files that reside on YOUR server. Surely you have access to them....
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #5
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts

    Lightbulb

    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.

  • #6
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #7
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts

    Exclamation

    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •