My app often needs to know the page name to pass to Google Analytics and various other uses. Hence, from http://dev.myapp.com/controller/action/value/ I want to get back the string "/controller/action/value/" for further manipulation (I need to ignore the domain). I can do this as follows: var Url = { getPage: function() { var segments document.location.href.split(''/'').slice(3).findAll(function(x){ return !x.empty() }); return ''/''.segments.join(''/'').''/''; } } document.location.getPage = Url.getPage; but I reckon there must be a more elegant way - can someone tell me what it is? Does prototype have anything special to say about document.location and it''s properties? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Why can''t you just use "document.location.pathname"? http://developer.mozilla.org/en/docs/DOM:window.location - kangax On May 22, 5:57 am, azymuth <david.winterbot...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> My app often needs to know the page name to pass to Google Analytics > and various other uses. Hence, fromhttp://dev.myapp.com/controller/action/value/ > I want to get back the string "/controller/action/value/" for further > manipulation (I need to ignore the domain). > > I can do this as follows: > var Url = { > getPage: function() { > var segments > document.location.href.split(''/'').slice(3).findAll(function(x){ > return !x.empty() > }); > return ''/''.segments.join(''/'').''/''; > }} > > document.location.getPage = Url.getPage; > > but I reckon there must be a more elegant way - can someone tell me > what it is? Does prototype have anything special to say about > document.location and it''s properties?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
No reason at all - apart from my previous ignorance of that property (now corrected). Cheers. On May 22, 3:03 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Why can''t you just use "document.location.pathname"?http://developer.mozilla.org/en/docs/DOM:window.location > > - kangax > > On May 22, 5:57 am, azymuth <david.winterbot...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > My app often needs to know the page name to pass to Google Analytics > > and various other uses. Hence, fromhttp://dev.myapp.com/controller/action/value/ > > I want to get back the string "/controller/action/value/" for further > > manipulation (I need to ignore the domain). > > > I can do this as follows: > > var Url = { > > getPage: function() { > > var segments > > document.location.href.split(''/'').slice(3).findAll(function(x){ > > return !x.empty() > > }); > > return ''/''.segments.join(''/'').''/''; > > }} > > > document.location.getPage = Url.getPage; > > > but I reckon there must be a more elegant way - can someone tell me > > what it is? Does prototype have anything special to say about > > document.location and it''s properties?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On May 23, 12:03 am, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Why can''t you just use "document.location.pathname"?http://developer.mozilla.org/en/docs/DOM:window.locationInstead of DOM 0 properties, it may be better to use DOM 2 HTML standard properties instead. Consider the URL and domain properties of interface HTMLDocument: <URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26809268 > Paste this into the address bar (please excuse wrapping): javascript:var re=new RegExp(''^.+'' + document.domain); alert((document.URL).replace(re,'''')); If the OP wants to remove the filename, that is pretty easy too. -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---