Jump to content
  • Advertisement
Taylor Spark

Sourcing an HTML script file from one site to another?

Recommended Posts

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??

Share this post


Link to post
Share on other sites
Advertisement

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.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!