Saturday 17 September 2011

eRaUI prototype - challenges

eRaUI prototype - challenges

An interesting challenge which has arisen while building the prototype is the difficulty in allowing the widget to communicate via ajax with the eRaUI domain while the widget itself is embedded on a website residing on a different domain / server. Due to cross-domain restrictions, it is not normally possible to communicate within a webpage with a domain other than that from which the page originated. Fortunately, there is a workaround which involves:
  • Instead of sending a simple data POST to the eRaUI server, we dynamically create a 'script' tag embedding a request for a target .js file. The data is sent to the .js in the querystring of the url.
  • The response from the server takes the form of a javascript call to a function pre-defined within the widget code, which accepts the data and makes it available for processing. Thus we circumvent cross-domain javascript restrictions which are fortunately not applicable to embedded requests for .js scripts, even when the script resides on a different domain.
  • Cookies can be handled too by means of an embedded iFrame. The iFrame creates a request for a page on the eRaUI server to which a uniquely generated id is sent by the widget. This could in theory be used to maintain user tracking across any domain in which the widget is embedded.
Deployment of eRaUI is simple - a single javascript include allows for the above functionality, thus making eRaUI easy to deploy upon any website.

No comments:

Post a Comment