Set Focus to Bottom of IFRAME element using JavaScript

Last Reply one month ago By dharmendr

Posted one month ago

how to focus cursor at end of the iframe body text.

<html>
<head runat="server">
</head>
    <iframe>
        <body> assgd fdsf dsf fds f dsfd svcvcvf  vcvcvf dvfv vvvs fdfdsfdsf
        </body
     </iframe>
</html>

I need to focus the cursor at the end of the line in iframe body when the page loads.

Posted one month ago

I will get back soon.


Posted one month ago

Hey sasi,

Please refer below sample.

HTML

CS.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <iframe id="iFrame" runat="server" src="Default.aspx"></iframe>
    </div>
    </form>
</body>
</html>

Default.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        window.onload = function () {
            window.scrollTo(0, document.body.scrollHeight);
            document.getElementById("TextBox1").focus();
        }        
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        Welcome To ASPSnippets.com
        <asp:TextBox ID="TextBox1" runat="server" />
    </div>
    </form>
</body>
</html>

Screenshot


Posted one month ago

 

<html>
<head runat="server">

</head>
<iframe>
<body> assgd fdsf dsf fds f dsfd svcvcvf  vcvcvf dvfv vvvs fdfdsfdsf
</body
 </iframe>
</html>

My code looks like above. I need to focus the cursor at the end of the line in iframe body when the page loads. help appreciated.


Posted one month ago

You can't display cursor on page. For displaying cursor you need to use TextBox.