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!

3
  • use localStorage? Commented Mar 12, 2019 at 15:34
  • It seems that you're looking for iframe Commented Mar 12, 2019 at 15:37
  • @brk How would I implement this if everything is being hosted on aws? Commented Mar 12, 2019 at 16:45

1 Answer 1

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>

Sign up to request clarification or add additional context in comments.

4 Comments

@hindmost added {credentials: "omit"}
I meant CORS issue. credentials option has no relation to CORS, it's about cookies.
BTW, the OP referenced AJAX-related post in his question. It's similar to yours except that post is a bit outdated now.
Does this bypass the same-origin policy?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.