简体   繁体   English

GreaseMonkey / UserScript仅重新加载页面的特定div?

[英]GreaseMonkey/UserScript to reload only a specific div of a page?

Is it possible to have JavaScript reload only a specific div of a page and replace it with the div of the loaded page? 是否可以让JavaScript仅重新加载页面的特定div并将其替换为已加载页面的div? It would be better if this only downloads the data from inside the div, but this is not necessary if it's not possible. 如果只从div内部下载数据会更好,但是如果不可能的话就没有必要了。 Since this is a UserScript/GreaseMonkey script, it is purely client side. 由于这是一个UserScript / GreaseMonkey脚本,因此它纯粹是客户端。 If this is possible, how can it be done? 如果可能的话,怎么办?

It is not possible to request only part of the page containing the div form the server, unless the contents of the div is being loaded separately on the website. 除非仅在网站上单独加载div的内容,否则不可能仅从服务器请求包含div的页面的一部分。

You can use XMLHttpRequest ( http://developer.mozilla.org/en/docs/XMLHttpRequest ) or GM_xmlhttpRequest ( http://wiki.greasespot.net/GM_xmlhttpRequest ) if on another domain to request the entire page, find the element in the response content, and replace the content on the page. 如果在另一个域上请求整个页面,请使用XMLHttpRequest( http://developer.mozilla.org/en/docs/XMLHttpRequest )或GM_xmlhttpRequest( http://wiki.greasespot.net/GM_xmlhttpRequest )查找元素。响应内容,然后替换页面上的内容。

The exact code you need will depend a lot on the content/website, but that should get you started. 您所需的确切代码在很大程度上取决于内容/网站,但这应该可以帮助您入门。

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

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