0

I have a website, lets call it 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.

I'm new to Javascript. 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. Even if I could figure that part out, I don't know how to insert that text into the HTML of the page.

I would appreciate any guidance!

Kane
  • 15
  • 3

1 Answers1

2

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>
AlexOwl
  • 869
  • 5
  • 11
  • @hindmost added `{credentials: "omit"}` – AlexOwl Mar 12 '19 at 15:41
  • I meant [CORS](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) issue. `credentials` option has no relation to CORS, it's about cookies. – hindmost Mar 12 '19 at 15:44
  • BTW, the OP referenced AJAX-related [post](https://stackoverflow.com/questions/3315235/javascript-access-another-webpage) in his question. It's similar to yours except that post is a bit outdated now. – hindmost Mar 12 '19 at 15:49
  • Does this bypass the same-origin policy? – Kane Mar 12 '19 at 16:44