Set Focus to Bottom of IFRAME element using JavaScript

Last Reply 3 months ago By dharmendr

Posted 3 months 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 3 months ago

I will get back soon.


Posted 3 months 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 3 months 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 3 months ago

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