简体   繁体   English

如何从其他页面添加div?

[英]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. 基本上我正在尝试从工作中的几个内部网站点中删除几个div。 and include them on a page I run locally (so I can look at one page instead of having 5 open). 并将它们包含在我本地运行的页面上(所以我可以看一页而不是打开5页)。 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. 我猜这是可能的JavaScript,但我是JavaScript的原始,所以我不知道我需要搜索什么来找到答案。 After I scrape the Div's from these other pages I want to add a refresh timer with something like setInterval() 在我从其他页面中删除Div之后,我想添加一个类似setInterval()的刷新计时器

This task is not as difficult as it should be, thanks to the glorious jQuery library... 由于光荣的jQuery库,这项任务并不像应该的那样困难......

$(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. 您可以使用XMLHttpRequest对象访问这些外部页面,获取它的HTML源并删除您想要的信息。

maybe this link can be useful: Auto refresh <DIV> using ajax 也许这个链接很有用: 使用ajax自动刷新<DIV>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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