views:

42

answers:

1

I'm using an external jQuery url parsing library http://github.com/allmarkedup/jQuery-URL-Parser to grab url segments for GET. The URL's i'm working with include one of two formats:

http://example.com/#name
or 
http://example.com/?name=name

Depending on the url im getting fed back, I want to use the url parsing library to construct a string. Either the hash tag value or the value of name. I'm running into an issue that I can't really query for an empty value using this library or I haven't found out how. Or I want to be able to figure out the URL format first. If I try to query for a url segment that it can't find, my application breaks. Any hints?

using http://example.com/?name=name

var url_anchor = jQuery.url.attr("anchor");
var url_query_name = jQuery.url.param("name");
if(url_anchor.length == 0){alert("The url anchor is: " + url_anchor)};

i'm expecting, obviously wrongly expecting :), the above to return NULL or Undefined but nothing happens.

A: 

Are you just trying to get "name" if url is passed in either format?

var param = jQuery.url.attr("anchor") ? jQuery.url.attr("anchor") : jQuery.url.param("name");
serg