0

I have an HTML page which I want to load on a click of a class using JavaScript. I am thinking of fetching that HTML using an iframe. This page contains content in the form of an overlay.

I have used .load() function of jQuery but it does not do anything. The pages I am working are both in same domain so I was hoping that the page would have loaded.

How can I achieve this?

$(".popup-layout").click(function() {

// I want to load an iframe here. Where should that iframe sit on the current page with diplay:none.




    });
Sam Thadhani
  • 585
  • 1
  • 10
  • 21
  • can you post your markup? or a fiddle would be nicer – Yaje Jun 26 '14 at 01:23
  • I was hoping that on click of the class .popup-layout, i fetch the page localhost:8080/abc.html using javascript. I have got just this javascript. – Sam Thadhani Jun 26 '14 at 01:28
  • possible duplicate of [How do I load an url in iframe with Jquery](http://stackoverflow.com/questions/7177080/how-do-i-load-an-url-in-iframe-with-jquery) – Yaje Jun 26 '14 at 01:34

3 Answers3

0

$('#result') is an <iframe id='result'>? You can't populate an iframe via jquery.load(). In fact, you don't need to. You can use a simple <div id='result'>

derpirscher
  • 14,418
  • 3
  • 18
  • 35
0

Here are 3 methods that can help you achieve that:

  1. Load the page on an <iframe> by changing its src. Example fiddle:

    YourFrameId.src = 'http://example.com';
    
  2. Load the page via an HTTP request and change the innerHTML of an existent element. Example fiddle:

    var req = new XMLHttpRequest();
    req.open('GET', 'http://www.mozilla.org/', true);
    req.onreadystatechange = function (aEvt) {
        if (req.readyState == 4 && req.status == 200) {
            YourElementId.innerHTML = req.responseText;
        }
    };
    req.send(null); 
    
  3. Use the location attribute of the document object:

    document.location = 'http://example.com'
    
arielnmz
  • 8,354
  • 9
  • 38
  • 66
0

I would use ajax loaded content over an iframe, just my opion though.

$(".popup-layout").click(function() {
       $.get("yourFile.html", function(data){
        $("#Content").html(data); // the div to load content in
       });
    });
Mark
  • 4,773
  • 8
  • 53
  • 91