I'm trying to pass a string into a function and weave it into a regular expression for use with the string search function.
Basically I'm trying to figure out the right syntax.
The hurdle here is that for some reason seach() only takes a regular expression as an argument.
I'm taking a file name, passing it into a function, and then checking the end of the current URL to see if it matches what was passed into the function.
For some reason, this version always comes up false, and I'm sure it has to do with my concatenation, but I just don't know how to concatenate a string INTO a regular expression, if it's even possible at all. Are they not two distinct data types?
The code is posted below.
var PageURL = document.URL;
function switcher(CaseName) {
CaseName = "/" + CaseName + "$/"
if (PageURL.search(CaseName) != -1){
alert("true");
}
else {
alert("false")
}
}
switcher("index.html");
Posts
stout's Amazon Wishlist | my lastFM
Contextually, I am modifying SWFObject so that a designer (read:cannot program in ASP.NET) can just feed in an easy line(s) into the code so they can have what flash document they want on which page.
if (PageURL.indexOf(CaseName) = (PageURL.length - CaseName.length))
might have to adjust the comparisons by 1 on a side though
you can also use a substring and try to match them but you'll have to do an additional check to make sure the lengths comply. so like:
if (PageURL.length >= CaseName.length & PageURL.substring(PageURL.length - CaseName.length) = CaseName)
stout's Amazon Wishlist | my lastFM
Yes, but that really doesn't make sense, we do web sites that have up to 200+ distinct pages, so some of those files are bound to have the same length... if I think that's what your implying.
The above about the regular expression object is pretty much what I need. I can pass in a string to a reg express. Hurray!
I believe that will be the solution. The way I check the URL may be crude but I'm certain it will work on any scale of a site.
Thanks
stout's Amazon Wishlist | my lastFM