📜 ⬆️ ⬇️

Cross Domain Data Exchange

Hello!
Today I would like to tell you about cross-domain data transfer. When I needed to transfer some string from one domain to another, I could not even imagine that there was so little information on the subject on the network.

Introduction

Actually it all started with the fact that a few months ago I registered on a free hosting . There I was offered to register a second-level domain, they promised 100 MB on the hard disk, good technical support (which is rare for free hosting sites) and all this is absolutely free and without any advertising. But, of course, there was some cost in the ointment, or rather not a spoon, but a whole barrel! Actually this resource does not provide any php or sql or other pleasant chips. Of course, deploying even a personal blog on this hosting is quite difficult. That's when I thought, what if my blog and other projects will lie on my full-fledged web server (which has a real external ip) and on that host only a file with an iframe. No sooner said than done. But here's the problem, the user can not find out the address of the page on which he is now. Site.ru will always be lit in the browser line as the main site is loaded in the frame. And this in turn means that he cannot share it with a friend or add to bookmarks, and this is not good.

Search for a solution

Actually, the idea of ​​how this problem should be solved did not take long to reap.
It is necessary with the help of js to get the url of the page loaded in the frame, get rid of everything superfluous (leave only the path), transfer it to the main page, replace the address. Water would be easy and understandable, but as it turned out, it is rather difficult to implement.
The fact is that the security policy prohibits accessing information in a frame if it is located on a different domain. This means that it is impossible to get the url of the page by a simple window.location.href to write it into a variable and get this variable in the main window in order to continue working with it. And here it is necessary to build a crutch.

"Crutch"

Actually, in a few days of searching, I found several options for implementing this task. Someone offered to work with the database, someone to write to the file, someone ... now I don’t even remember.
In general, they all did not really like me, and then I began to invent my own crutch.
')
For some reason I could not put the js code here, so I threw it on a special server:
index.html on hosting
Inside every page on your web server

Now let's see what yes how:
When a user visits the site at site.ru , js in the index.html file processes the request, finds out where we want to go (in this case, roll) and loads the corresponding page from the server into the frame.

When a user navigates to another page, our index.html is sent the address where the user is currently located, and he in turn puts it in the page.

Conclusion

That's how I got a full-fledged web server, which I can pick as I just want, without investing a single ruble in it.

Of course, using such a method for large projects is not possible, but for the home page, blog, photo gallery, or raising a server completely.

There are several points that I have not yet figured out. The most important of these is indexing by search engines.

Thank you all for your attention!

Source: https://habr.com/ru/post/111643/


All Articles