简体   繁体   English

如何使用Javascript将另一个网页上的文本显示到另一个页面上?

[英]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.

相关问题 如何使用 PHP 或 JavaScript 在网页正文中显示描述元标记的内容? - How can I use either PHP or JavaScript to display the contents of the description meta tag in the body text of a web page? 如何使用Perl从使用JavaScript动态生成的网页中获取文本? - How can I use Perl to grab text from a web page that is dynamically generated with JavaScript? 如何将Javascript函数的值显示在HTML页面上? - How to display value from a Javascript function onto an HTML page? 如何在JavaScript的同一页面上显示文本内容? - How can I display text content on the same page in JavaScript? 如何使用 JavaScript 等待单击一个页面,然后将存储在带有对象的数组中的数据显示在另一页上 - how can I use JavaScript to wait for a click on one page then take data stored in an array with objects to display it's content on another page 如何使用 HTML/Javascript 从另一个页面显示某些内容? - How can I display something from another page by using HTML/Javascript? 如何将表单值从一页传递到另一页? - How can I pass form values from one page onto another? 如何将某些HTML从一个页面转换为另一页面的表单? - How can I get certain HTML from one page into a form onto another? 当用户单击网页时,如何从网页中删除一个元素,并使用javascript在其位置显示另一个元素 - How do i remove an element an element from my web page when a user clicks on it and display another element at it's place using javascript 如何从 web 页面上的文件中读取文本 - How can I read text from a file on a web page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM