1

I am trying to get a part of the page, for example http:/example.com/home.html, that home has a div with some id="content" , id like to set an iframe and display only the "content" ... i have tried with load (with jquery) as this post says

http://stackoverflow.com/questions/4249809/reload-an-iframe-with-jquery

but no results yet, any idea how to do it? in jquery or direct php.

Thanks in advance.

jpganz18
  • 5,508
  • 17
  • 66
  • 115
  • Do you have control over the content that you want to grab? if so, do you need to place the content inside an iframe? or could you place it as an ajax response inside a div? – IngGaberick Aug 09 '13 at 04:01
  • As you tag with PHP, do you want to grab it by PHP's cURL ? – Raptor Aug 09 '13 at 04:02
  • tahnks, I dont have control of the content, its on a website that sale cars, i just wanna show the stuffs without showing the logos and so on, only the content. everytime i try, it throws and error, but i dont know what kind... it doesnt say any (with firebug), @ShivanRaptor if is possible to grab it with php, id do it, thanks for reply – jpganz18 Aug 09 '13 at 04:19

3 Answers3

2

Perhaps you don't need to use an iframe - they are generally used for embedding another website, which is not quite what you need. Instead, make an ajax request to the url you need, and use jquery to parse the response and fetch the div you need to load.

Example:


$.ajax({
  type: "GET",
  url: "http://stackoverflow.com/questions/4249809/reload-an-iframe-with-jquery",
  success: function(r) {
    var content = $(r).find("#content");
    //now you have the content div stored in a variable
  }
});
hesson
  • 1,812
  • 4
  • 23
  • 35
  • Ive been trying this method, due sounds very good, but... seems like is something im not doing, it returns an error, but doesnt say which one :s – jpganz18 Aug 09 '13 at 04:38
  • The issue to be aware of, and why this may not have worked, is cross domain restrictions. There are ways around it though: http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain – Jeremy Harris Dec 27 '16 at 18:10
0

perhaps you can try $.get function from jquery to get only certain elements content

https://stackoverflow.com/a/9713037/1781996

Community
  • 1
  • 1
shashikant_
  • 122
  • 5
0

Ok, here's my suggestion. If you want to grab just a piece of content from the page, you can use an ajax call, storage the answer inside a variable and use the split jquery function. Lets say that the page that you want to load is a series of divs, inside the div that you want you can place something like at the begining and at the end of the div, after that the rest will be easy, when you get your data from the ajax call you use something like:

var answer = (you ajax response) ;
var content = answer.split("<!-- SPLIT CONTENT -->");
$('#MyCoolContainer').html(content[1]);

By doing this, you'll split the answer in 3 parts, the first one content[0] will be everything before the first comment, content[1] will be the content of the div you want, and content[2] will be everything after the closing SPLIT CONTENT. then you just place that content inside a div.

IngGaberick
  • 319
  • 1
  • 9