You must Sign In to post a response.
  • Category: JQuery

    Load the local file in iframe using jquery

    I have the html file on my desktop.
    I want to read the content of this html file and display on iframe.
    Below the steps:
    on my page I have a browse option of "input type=file".
    By using this i will select the html file.
    After selection the content of html need to be rendered on my iframe.

    can any one check this..
  • #755168
    You can use following code snippet for local file in iframe using jquery

    <iframe src="content/Yourfile.html" width="100" height="100"></iframe>
    <iframe src="http://www.Yourexamplesite.com/file.html" width="100" height="100"></iframe>

  • #755222
    it is simple just place the content of the path file in to iframe

    but i dont know what error you are getting

    <body>
    <iframe src="iframe.html"></iframe>
    </body>

  • #755228
    Simply set the below code to load a local file in iframe



    $(#IframeIf).load("/Yourfilename.html");

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #755248
    Hi,
    use the below code for your references:

    /// Html Content


    here only u create the html content and Iframe div and call this div inside the jquerry along with ur "Html" file.

    <html>
    <head>
    </head>
    <body>
    Some text
    <div id="iframediv"></div>
    </body>
    </html>


    //// Jquerry

    $.ajax({type: "POST",url:"content/file.html",dataType:"html",success: function(data) {$('#iframediv').html(data);}});

    hope it will work for uuu..


    Thanks,
    chitaranjan

  • #757561
    Hi,

    if you want to display it satically then just refer that path to iframe src property attribute then it will load the html page in iframe

    or else if you want to set the same with dynamically then write a function to load the content in which refer the url to src attribute of the iframe.


    please refer the code snippet bellow


    function setiframeurl(url)
    {
    $('#frameid').attr('src',url);

    }

    by calling this function your iframe will load the content referred in the url.

    Regards
    SriSunny


  • Sign In to post your comments