开发者

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.


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.)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜