Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2011
    Location
    UK
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    [JQuery] Trouble replacing inline HTML with external HTML page

    Hi,

    I'm a novice with javascript though I've hacked scripts before to satisfy my own requirements - however this is too tricky for me to work out alone. Any help or guidance to solving this is very much appreciated.

    So I'm looking to throw up a popup lightbox on my page after a few seconds delay. The code I have is:

    Code:
    <script type='text/javascript' src='jquery.js'></script>
    <script type='text/javascript' src='lightbox.js'></script>
    
    <script type="text/javascript">
    var popup_domination = {"defaults":{"Name":"Your First Name...","Email1":"Your Email Address..."},"delay":2,"cookie_time":1,"center":"Y","cookie_path":"\/","show_opt":"open","unload_msg":"Would you like to signup to the newsletter before you go?","impression_count":0,"output":"<div class=\"popup-dom-lightbox-wrapper\" id=\"popup_domination_lightbox_wrapper\" style=\"display:none\">my content goes in here<\/div>"};
    </script>
    You'll notice the content is inline, but what I'd like to do is use an external HTML file - it saves me having to escape all the HTML within the javascript y'see...

    I'm guessing the "output":"<div class=\"popup-dom-lightbox-wrapper\" id=\"popup_domination_lightbox_wrapper\" style=\"display:none\">my content goes in here<\/div>" is what I need to change - but how could I load and external HTML file in here instead?

    Many thanks,

    Rob.

  • #2
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    You would have to use AJAX for that. jQuery actually makes that very easy; it would look something like that:

    PHP Code:
    $.get('/url/of/the/file.html', function (html) {
        
    // Whatever you want to do. The html parameter holds the contents of your HTML file.
    }); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •