4

I'm learning couchapp and it looks pretty easy to query database items.

But I have items with attachments, and I'd like to add hyperlinks to the attachments:

 <a href="/databasename/{{id}}/{{attachment}}">{{description}}</a>

I can get id, attachment and description setup properly, but how do I get the current database name (or URL) from within a couchapp javascript function?

Jason S
  • 184,598
  • 164
  • 608
  • 970

1 Answers1

3

If you don't want to use relative urls, you can fetch the db name in following way:

var dbname = unescape(document.location.href).split('/')[2]

since your href looks like: http://host:port/dbname/doc...

This is also the code jquery.couch.app.js uses. So if you are using it, it's available for you in initialization code:

$.couch.app(function(app) { alert(app.db.name); });
Bartosz
  • 3,318
  • 21
  • 31
  • cool, i'll give that a shot (maybe store it in a state variable or something for functions that don't have `app` as an input parameter) – Jason S Nov 20 '11 at 23:14