Advertisement

Sourcing an HTML script file from one site to another?

Started by December 08, 2018 03:25 AM
1 comment, last by hplus0603 5 years, 11 months ago

I was wondering, Is it digitally possible to Source a line of HTML from another site? For example, I have a Key-generator Site and I want to Source the key directly onto my website, so it auto updates in real-time whenever the Key is Changed. (don't ask why i'm using a keygenerator I just want to know if its possible, the site its on autoredirects using a referrer check to see where you entered the website from, and if its false, it send you to an annoying ad human survey thing....) anyways I just need a way to source the simple little line of text to my site

Is it possible to do something like this:

<span src="Site.com###head > ElementSelectorHere" </span>

or something similar where I can link the location of the html via a Copied Selector, Javascript or XPath? If so please give me a base example to go off of??

In general, no, you cannot do this unless the site explicitly declares that it's OK to come from that site.

The reason is that you want to avoid "cross site scripting" and "cross site request forgery." In fact, there is a whole machinery in the web browser and server to make sure that you don't execute code inside one context that was sourced from some unapproved other context. Each time there's a bug in a browser in this area, some bank gets attacked and people's phones burn up from mining cryptocoins.

(Consider: If yoursite.com could have an inline element that read from bankofamerica.com and then used the data, then any user that happened to have a valid web session to bankofamerica.com when they visited your site, would be open to whatever your site decided to do.)

This is all spelled out in its Rube Goldberg complexity in the specification for cross-origin resource sharing. Check for example https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

Now, if all you need is for the user to read the data, the code from your site doesn't need to read the data, then you can put in content from other sites by including an IFRAME or an IMG tag. Both of those allow references to third party sites, and display the result of the reference to the user. However, it doesn't allow the code on your own site to "look inside" the tag and extract the contents. (This gets extra complex when you use canvas, and opengl textures, and is an endless source of frustration for websites wanting to print or save "screenshots" of the site under their own control.)

There is limited styling of the layout of the IFRAME on the page, but you can not style or otherwise affect what goes on the inside of the IFRAME. If that's still acceptable for you, then I'd recommend that you attempt to express whatever you need using that primitive.

 

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement