Using an Array to get parts of the URL
Often when I am developing a web site, I will need to get a handle on different pieces of the URL. Sometimes I will need just the database path and other times I might need the document ID. I came up with an easy function that uses the split method to get the URL into an array and retrieve whatever piece of it I needed. The function below is built to work with Quickplace databases:

function getHomeFolder(returnValues) {
  var temp = new Array();
  temp = document.location.href.split('/');
  var rv = "";

  var protocol = temp[0];
  var server = temp[2];
  var qp = temp[3];
  var sub = temp[4];
  var db = temp[5];
  var view = temp[6];
  var doc = temp[7];
  
  if (returnValues.indexOf('1') != -1) { rv = rv + protocol + '//';}
  if (returnValues.indexOf('2') != -1) { rv = rv + server + '/';}
  if (returnValues.indexOf('3') != -1) { rv = rv + qp + '/';}
  if (returnValues.indexOf('4') != -1) { rv = rv + sub + '/';}
  if (returnValues.indexOf('5') != -1) { rv = rv + db + '/';}
  if (returnValues.indexOf('6') != -1) { rv = rv + view + '/';}
  if (returnValues.indexOf('7') != -1) { rv = rv + doc;}
  return rv;
}

The above function could be easily generalized to be able to be used in any database on a Domino server or any regular web page. It's much easier than looping through the href using indexOf() or substring(). In fact, you can use split to create a JS version of Rocky's favorite @Function, @Word.

function atWord(fullstring, sep, wordno) {
  var temp = new Array();
  temp = fullstring.split(sep);
  if (temp.length > wordno) {
    return temp[wordno - 1];
  } else {
    return false;
  }
}

<< Previous Document / Next Document >>
    Be the first in the world to comment on this entry!!!
Post A Comment
Subject: (required)
Name: (required)
Email: (required)
Web Site:
Comment:(No HTML - Links will be converted if prefixed http://)

Remember Me?