简体   繁体   中英

How can I include a div from another page?

Basically I'm trying to scrape a few divs out of several of the intranet sites at work. and include them on a page I run locally (so I can look at one page instead of having 5 open). I'm guessing this is possible with JavaScript but I'm primitive with JavaScript so I'm not sure what I need to search for to find the answers. After I scrape the Div's from these other pages I want to add a refresh timer with something like setInterval()

This task is not as difficult as it should be, thanks to the glorious jQuery library...

$(document).ready(function() {
  // Repeat this for each of your URLs
  $.get("URL", function(data) {
    var resp = $(data); // Now you can do whatever you want with it
    $("#ID_OF_DIV", resp).appendTo("body");
  });
  // End Repeat

  setTimeout(function() {
    location.reload(true);
  }, 10000); // Refresh every ten seconds
});

You can to access those external pages using an XMLHttpRequest object, grab it's HTML source and strip just that information you want.

maybe this link can be useful: Auto refresh <DIV> using ajax

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM