<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://developers.pando.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>Pando Developer Tools - Using PandoAPI.js Installed Cookie Check - Comments</title>
 <link>http://developers.pando.com/using-pandoapi-js-installed-cookie-check</link>
 <description>Comments for &quot;Using PandoAPI.js Installed Cookie Check&quot;</description>
 <language>en</language>
<item>
 <title>Using PandoAPI.js Installed Cookie Check</title>
 <link>http://developers.pando.com/using-pandoapi-js-installed-cookie-check</link>
 <description>&lt;p&gt;
In addition to providing &lt;a href=&quot;/howto-javascript-previews&quot;&gt;package info service&lt;/a&gt;, the &lt;a href=&quot;/javascript-access-pandoapi-js&quot;&gt;PandoAPI.js&lt;/a&gt; javascript library also provides a Pando &quot;install&quot; check service.  We (Pando) set a cookie named &quot;installed&quot; in the pando.com domain whenever we determine a user has Pando installed.  Because it runs from a pando.com domain, PandoAPI can inspect this cookie.  If a user has this cookie set, you can be reasonably sure they have Pando installed.  If they do not, they still may have Pando installed but have removed the cookie.
&lt;/p&gt;
&lt;p&gt;To use this service on your own site, you pass callback function to the PandoAPI.hasPando() method. The callback function takes a single argument.  This function is then called by the PandoAPI method, with the argument set to true or false depending on the status of the installed cookie.  This allows you to modify the content of your pages with javascript depending on the cookie status.  In this example we&#039;ll use this method to prepend &lt;a href=&quot;/promote-subscription-pando-subscribe&quot;&gt;&lt;code&gt;pando:subscribe?&lt;/code&gt;&lt;/a&gt; to pando channel subscription links for users who have this cookie set, to provide a one-click subscription experience for Pando users.
&lt;/p&gt;
&lt;p&gt;
First, we&#039;ll need to make sure we include the Pando javascript API in our &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; section:
&lt;/p&gt;
&lt;blockquote&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://cache.pando.com/soapservices/PandoAPI.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/div&gt;
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;
Then, the below script does the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Uses the PandoAPI.hasPando() method to store a boolean variable with the result from the hasPando method&lt;/li&gt;
&lt;li&gt;Defines a list of links indexed by their DOM id&lt;/li&gt;
&lt;li&gt;After the window loads, rewrites links with appropriate &lt;code&gt;pando:subscribe?&lt;/code&gt; URLs if the Pando installed cookie is detected&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can follow along with the comments:
&lt;/p&gt;
&lt;blockquote&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;	&amp;nbsp; &lt;br /&gt;	&amp;nbsp; // Assume Pando is not installed&lt;br /&gt;	&amp;nbsp; pandoInstalled = false;&lt;br /&gt;	&amp;nbsp; &lt;br /&gt;	&amp;nbsp; // Pass a simple callback function that sets pandoInstalled to true if cookie is present&lt;br /&gt;	&amp;nbsp; PandoAPI.hasPando(function(i){ if(i == true) pandoInstalled = true; });&lt;br /&gt;	&amp;nbsp; &lt;br /&gt;	&amp;nbsp; // Define list of channel feeds and pages&lt;br /&gt;	&amp;nbsp; var subscribeLinks = {&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#039;pandomonium&amp;#039;: {&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#039;channelPage&amp;#039;: &amp;#039;http://channels.pando.com/channel/pandomonium&amp;#039;,&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#039;channelFeed&amp;#039;: &amp;#039;http://feedburner.pando.com/pando/pandomonium&amp;#039;&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp; },&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#039;projectpedal&amp;#039;: {&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#039;channelPage&amp;#039;: &amp;#039;http://channels.pando.com/channel/projectpedal&amp;#039;,&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#039;channelFeed&amp;#039;: &amp;#039;http://feedburner.pando.com/pando/projectpedal&amp;#039;&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp; },&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#039;rocketboomhd&amp;#039;: {&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#039;channelPage&amp;#039;: &amp;#039;http://channels.pando.com/channel/rocketboomhd&amp;#039;,&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#039;channelFeed&amp;#039;: &amp;#039;http://feedburner.pando.com/pando/rocketboomhd&amp;#039;&lt;br /&gt;	&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;	&amp;nbsp; };&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Do not try to use pandoInstalled until the page is loaded; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // the callback function may not have run yet and we want to&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // make sure our links are ready to modify&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; window.onload = function(){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // If Pando is installed, rewrite the links&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(pandoInstalled == true) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // For each link&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(channelId in subscribeLinks) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Find the link to modify&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; link = document.getElementById(channelId);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Change the href attribute to a pando:subscribe? link with the feed URL&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; link.href = &amp;#039;pando:subscribe?&amp;#039; + subscribeLinks[channelId][&amp;#039;channelFeed&amp;#039;];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/div&gt;
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;
Then, in the body of your page, define your links with the appropriate id and with URLs that will work if javascript is not enabled:&lt;/p&gt;
&lt;blockquote&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&amp;nbsp; &amp;lt;ul&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;http://channels.pando.com/channel/pandomonium&amp;quot; id=&amp;quot;pandomonium&amp;quot;&amp;gt;Pandomonium&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;http://channels.pando.com/channel/projectpedal&amp;quot; id=&amp;quot;projectpedal&amp;quot;&amp;gt;Project Pedal&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;http://channels.pando.com/channel/rocketboomhd&amp;quot; id=&amp;quot;rocketboomhd&amp;quot;&amp;gt;Rocketboom&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/ul&amp;gt;&amp;nbsp; &lt;/code&gt;&lt;/div&gt;
&lt;/p&gt;&lt;/blockquote&gt;&lt;/p&gt;
&lt;p&gt;
A version of this script lives on a stand-alone page &lt;a href=&quot;/static/pandojsapi-example/cookie-check.php&quot;&gt;here&lt;/a&gt;.  Feel free to view the source and borrow what you need and ask any questions below.  (This page also includes a server-side cookie inspection so you can tell when viewing the page whether you have the Pando &quot;installed&quot; cookie set, for testing purposes).
&lt;/p&gt;
</description>
 <comments>http://developers.pando.com/using-pandoapi-js-installed-cookie-check#comments</comments>
 <category domain="http://developers.pando.com/web-developers">Web Developers</category>
 <pubDate>Mon, 30 Jul 2007 13:00:57 -0400</pubDate>
 <dc:creator>scott</dc:creator>
 <guid isPermaLink="false">188 at http://developers.pando.com</guid>
</item>
</channel>
</rss>
