SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2002
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Using the moveToElementText Function for a frame within an iframe

    Hi,

    I have used the following script in a no-frame document to replace text of a specified span (id=element142) with no problems.

    Code:
     
    function GenerateCode()
    {
    r=document.body.createTextRange();
    r.moveToElementText(element142);
    r.text="Newly generated text"
    }
    However, I have a page with an iframe, and the iframe has two frames within itself. I am using a modified version of the previous function in the parent frame to replace the text of a span in the frame inside the iframe. All I did was add the name of the iframe and the name of the second frame (myEditor.page) to the r variable to specify that the element is not in the parent document, but is two frames deeper....

    Code:
    function GenerateCode()
    {
    r=myEditor.page.document.body.createTextRange();
    r.moveToElementText(element142);
    r.text="Newly generated text"
    }
    This causes an 'element142' is undefined error, even though there is a span in that frame with that id. What am I doing wrong?

    Thanks in advance,
    David

  2. #2
    SitePoint Member
    Join Date
    Dec 2003
    Location
    Outer Slobovia
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dcbraund
    Hi,

    I have used the following script in a no-frame document to replace text of a specified span (id=element142) with no problems.

    Code:
     
    function GenerateCode()
    {
    r=document.body.createTextRange();
    r.moveToElementText(element142);
    r.text="Newly generated text"
    }
    However, I have a page with an iframe, and the iframe has two frames within itself. I am using a modified version of the previous function in the parent frame to replace the text of a span in the frame inside the iframe. All I did was add the name of the iframe and the name of the second frame (myEditor.page) to the r variable to specify that the element is not in the parent document, but is two frames deeper....

    Code:
    function GenerateCode()
    {
    r=myEditor.page.document.body.createTextRange();
    r.moveToElementText(element142);
    r.text="Newly generated text"
    }
    This causes an 'element142' is undefined error, even though there is a span in that frame with that id. What am I doing wrong?

    Thanks in advance,
    David
    The object is undefined since it's not to be found on the script page, but buried down in myEdiotr.page where the TextRange object resides. Therefore you need to point to the object. The code might be as follows:
    Code:
    function GenerateCode()
    {
    r=myEditor.page.document.body.createTextRange();
    r.moveToElementText(myEditor.page.element142);
    r.text="Newly generated text"
    }
    Hope this helps.


Bookmarks

Posting Permissions

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