[英]How can I use Javascript to display text from another web page onto a different page?
I have a website, lets call it abc.com. 我有一个网站,称其为abc.com。 I need to automatically retrieve text from another page called static.abc.com/pluginchangelog.txt and display the text at the top of that page on abc.com/plugin. 我需要自动从另一个名为static.abc.com/pluginchangelog.txt的页面检索文本,并在abc.com/plugin的该页面顶部显示文本。
I'm new to Javascript. 我是Java的新手。 I've searched and searched, but I haven't been able to find a definitive answer. 我已经搜索了,但是还没有找到确切的答案。 I found this page, Javascript access another webpage , but I'm not sure how to implement this for the use that I need. 我找到了此页面, Javascript访问了另一个页面 ,但是我不确定如何实现此功能以实现所需的用途。 Even if I could figure that part out, I don't know how to insert that text into the HTML of the page. 即使我能弄清楚那部分,我也不知道如何将文本插入页面的HTML中。
I would appreciate any guidance! 我将不胜感激!
Use fetch to get text 使用提取获取文本
Then edit content on your page how you want 然后根据需要编辑页面上的内容
fetch("https://example.com/pluginchangelog.txt", {credentials: "omit"}).then(resp => resp.text()).then(text => { // do anything you want with text content.innerText = text })
<html> <body> <p id="content"/> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.