Site Home  »  Access Your App From a Web Page

Access Your App From a Web Page

Tags:  

This page is a first draft, which will be revised and improved. Please leave us a note on the community page regarding any issue.

Use Crossrider's appAPI from your Site

Crossrider developers can expose the appAPI to their verified domain's page. (You can verify your domain from the Apps Edit panel)

Exposing the appAPI to your site's pages can help with knowing wether your user has already installed your app, read and update data saved on the browser with the appAPI.db() method, do cross domain requests and basically everything you can do with the appAPI from the extension code.

To expose appAPI to the page do the following:

Exposing the appAPI

<script src="http://crossrider.com/crossrider.api.js" type="text/javascript"></script> 
 <script
 var appAPI;
 crossriderAPI.askForAsyncAppAPI(YOUR_APP_IDfunction(data)  {  
 appAPI data;  
 });
</script>

(Pay attention this method is async due to Chrome limitations)

As you are exposing the async api - all appAPI calls that you are doing should have a callback.
So every API method without a callback - simply add the first parameter as a callback function, the one that has a callback function stays the same.

So for example, the appAPI.db.get you are doing, should look like this:

appAPI.db.get(function(data) {
  // your code here
}, "test")); 
 
appAPI.db.set(function() { 
  // do something else 
}, "db_key_name", db_value);  

Exposing the appAPI to an iFrame
You can also expose the appAPI to an iframe with a src of your trusted domain. This is very useful when you need to include a sidebar to each page with content from your own website and want to use the appAPI object from that page.

There is a small addition you will have to make in your code inorder for this to work on Chrome as well. (In Firefox and IE it works seamlessly)

First, you will need to give a unique ID to your iframe, for example:
<iframe src="http://yourtrusteddomain.com/iframe.html" id="my_iframe_id"></iframe> 
Second, you will need to add the following code to your app code:
if (appAPI.platform == "CH") appAPI.asyncAPI.setTargetIframe("my_iframe_id");

This will make sure that Chrome will know which iframe on the page did the request and where it should send the callbacks to.






Aaron (Guest) 192 - days ago 
Is it possible to use Crossrider's appAPI from any web page? My app will be injected into web page doesn't belongs to my domain, and want to use appAPI's db api to save user's setting. Could I achieve this without inject appAPI to web page?
shmueli 192 - days ago 
Aaron,
Please see this: <a href="http://getsatisfaction.com/crossrider/topics/need_to_access_appapi_functions_from_web_pages_i_doesnt_own">http://getsatisfaction.com/crossrider/topics/need_to_access_appapi_functions_from_web_pages_i_doesnt_own</a>
Tobias (Guest) 11 - days ago 
appAPI.installer.getParams() isnt working - are the params saved in the DB to access from an external page?
Tobias, appAPI.installer.getParams() is not exposed to the page.

Please see this thread:
https://getsatisfaction.com/crossrider/topics/appapi_installer_getparams_in_exposed_appapi
Post a comment

Your Name or E-mail ID (mandatory)






 RSS of this page

Written by:   Version:   Last Edited By:   Modified