cursor position

I have an iframe like:

    <iframe id = "ddd"></iframe>

the user can type some text in it when design mode is on.

Is there a function I can use to automatically move the cursor to the end of the iframe?

Thanks
LVL 7
minnirokAsked:
Who is Participating?
 
dbrittCommented:
Absolutely.

But as was suggested, you're asking about the "caret", not the "cursor" ;)

Enjoy! ^^

======================================
test.html
======================================

<html>
<head>
      <title>Test Page</title>

      <script language="JavaScript" type="text/javascript">
      
      function runTest()
      {
            var bdy = ddd.document.body;

            if (bdy.createTextRange) {
                  var range = bdy.createTextRange();
                  range.collapse(true);
                  range.moveEnd('character', bdy.innerHTML.length);
                  range.moveStart('character', bdy.innerHTML.length);
                  range.select();
            }
      }
      
      </script>
</head>

<body>

      <input type="button" value="Run Test" onclick="javascript:runTest();">

      <br><br>

      <iframe id="ddd" src="iframe.html"></iframe>

</body>
</html>


======================================
iframe.html
======================================

<html>
<head>
      <title>The IFrame</title>
</head>

<body contenteditable="true">
Howdy

<br><br>

<span id="test"></span>

<br>

:)
</body>
</html>
0
 
Samuel LiewCommented:
When you mean cursor, do you mean mouse cursor or text cursor? You definitely can't move the mouse cursor.
0
 
UnexplainedWaysCommented:
You might want a textarea or textbox for that.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.