CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2002
    Location
    PA
    Posts
    36

    assigning innerHTML to variable

    here's an interesting one i think:

    i'm trying to do this:

    var theString = mytext.document.body.innerHTML;
    alert(theString);

    where mytext is an IFRAME element...the only IFRAME element on the page...and although i keep getting the alert with the innerHTML in it exactly like i want (for a test)...i also get an error that says: object required.

    now the interesting thing is that i've done this same thing other places in the app and it's worked fine! hmmm....

    ----------
    my html looks like this:

    <td><IFRAME class="mytext" width="<%= strWidth %>" ID="mytext" height="100%"></IFRAME></td>

    and my javascript looks like this:

    // Initialize everything when the document is ready
    var YInitialized = false;
    function document.onreadystatechange()
    {
    YInitialized = true;
    var i, s, curr;
    var newEvt;
    mytext.document.open();
    mytext.document.write("<BODY bgcolor=\"#<%= strColor %>\" >");
    mytext.document.write("<%= jsString %>");
    mytext.document.write("</body>");
    mytext.document.close();
    mytext.document.designMode="On";
    mytext.focus();
    healBorders();
    var theString = mytext.document.body.innerHTML;
    alert(theString);

    }

    you can see that i've saved HTML code in a field in a db and upon loading this page i write it to the IFRAME using asp and javascript...
    -------------
    any help would be real, real nice.
    b

  2. #2
    Join Date
    Aug 2002
    Location
    PA
    Posts
    36

    the answer...

    well...it wasn't a stupid question...i just didn't know the intricacies of "DesignMode"...

    apparently the reason the original code fragment wouldn't work:

    document.saveForm.html.value = mytext.document.body.innerHTML;

    was because previous to this i also had this line of code:

    mytext.document.designMode="On";

    and according the the documentation from microsoft on "designmode" (see below)...of course it wouldn't work!

    in the other places in my code where i had the original statement designMode was Off. go figure.

    _____________________
    Remarks - Microsoft

    You can use the designMode property to put Microsoft® Internet Explorer into a mode where you can edit the current document.

    While the browser is in design mode, objects enter a UI-activated state when the user presses ENTER or clicks an object that has focus, or when the user double-clicks the object. Objects that are UI-activated have their own window within the document. You can modify the UI only when the object is in a UI-activated state.

    You cannot execute script when the value of the designMode property is set to On.
    _______________________________________

    situation vindicated.
    (i hope this helps somebody, somewhere, sometime!)
    b

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured