Srikanth Rayabhagi
Srikanth Rayabhagi

Reputation: 1443

WebSQL Databases between two different pages?

Is there any particular way in which we can access the Web SQL Database of one page, by other page. To make it more clear, suppose a.com creates the database DB and store some info. Now b.com comes and want to access the same database DB. Is there a way? Or are there any alternatives to do this? I tried to implement in HTML5 and Javascript but the databases as well as the localStorages are confining only to particular pages, I want this to be cross the pages.

Upvotes: 2

Views: 1472

Answers (2)

Michael Mullany
Michael Mullany

Reputation: 31750

You can accomplish this by including a utility iFrame with a database access script from b.com in your a.com pages and vice versa. You can then use cross document messaging to transfer information. Note that postMessage only transmits a simple string and if you're trying to pass structured information then a.com and b.com will have to agree on a serialization. So...it's a hack.

Upvotes: 0

Sean Vieira
Sean Vieira

Reputation: 160005

If you want a script on http://one-domain.com/ to be able to read from the database of http://another-domain.org then no -- the Same Origin Policy is applied to localStorage and Web SQL databases, which means that only scripts running on the same domain as the script that created the database are allowed to have access to the database.

Your best bet in that case would be to send the data from one-domain back to the server and have the server of one-domain push the data over to another-domain (or else, if they are on the same network, provide a shared resource they can communicate over.)

Upvotes: 2

Related Questions