#

 

ich möchte dass eine Funktion oder Programm nach dem Laden einer Webseite ausgeführt wird.

 

Code Beispiel

Im Beispiel soll ein Div-Feld mit HTML geladen werden.

 

 

Lösung:

Wenn ein script-Block an das ende der Webseite geschrieben wird und mit jQuery nach $(document).ready geprüft wird,

dann führt der document.loaded-Event zum Aufruf der Function

$(document).ready(load_function);

 

 

Code Beispiel

1) jQuery

@*------------< jQuery-script >------------*@

<script type="text/javascript" src="~/lib/jquery/dist/jquery.js"></script>

<script>

    //----< events >----

    $("#btnLoadHTML").click(load_HTML_to_Div);

    $("#ctlEditor_HTML").on("input", transfer_Text);

    $(document).ready(load_HTML_to_Div);

    //----</ events >----

 

    //----< functions >----

    function load_HTML_to_Div() {

        var sHTML = $("#ctlEditor_Text").val();

        $("#ctlEditor_HTML").empty();

        $("#ctlEditor_HTML").append(sHTML);

    }

    function transfer_Text() {

        var sText = $("#ctlEditor_HTML").html();

        $("#ctlEditor_Text").val(sText);

    }

    //----</ functions >----

</script>

@*------------</ jQuery-script >------------*@

 

 

jQuery, Asp Core Mvc

@{

    Layout = null;

}

<div>

    <form asp-action="demo_jQuery_01_post">

        <div class="form-group">

            <input type="submit" value="Send" class="btn btn-default" />           

        </div>

        <br />

        <div class="form-group">

            Editor HTML (div)

            <br />

            <div contenteditable="true" id="ctlEditor_HTML" name="ctlEditor_HTML" style="height:100px;width:90%;overflow:auto;border:1px solid red;">

               

            </div>

            <br />

           

 

            <br />

            Editor Text (textarea)

            <br />

            <textarea class="form-control" id="ctlEditor_Text"  name="ctlEditor_Text" style="height:100px;width:90%; overflow:auto;border:1px solid blue;color:gray;">

                    @ViewData["Text1"]

            </textarea>

        </div>

    </form>

    </div>

<button id="btnLoadHTML">load HTML to Div</button>

 

 

@*------------< jQuery-script >------------*@

<script type="text/javascript" src="~/lib/jquery/dist/jquery.js"></script>

<script>

    //----< events >----

    $("#btnLoadHTML").click(load_HTML_to_Div);

    $("#ctlEditor_HTML").on("input", transfer_Text);

    $(document).ready(load_HTML_to_Div);

    //----</ events >----

 

 

    //----< functions >----

    function load_HTML_to_Div() {

        var sHTML = $("#ctlEditor_Text").val();

        $("#ctlEditor_HTML").empty();

        $("#ctlEditor_HTML").append(sHTML);

    }

 

    function transfer_Text() {

        var sText = $("#ctlEditor_HTML").html();

        $("#ctlEditor_Text").val(sText);

    }

 

 

    //----</ functions >----

</script>

@*------------</ jQuery-script >------------*@

 

Mobile

.

soap2day