How can I place document.location.search into a variable w/o the '?' Is there a simple regex, or can I just ignore the first character?
A:
You can simply replace the "?" character with an empty string:
var searchWithoutQuestionMark = document.location.search.replace('?', '');
Steve
Steve Harrison
2009-04-18 06:51:40
+6
A:
No problem
window.location.search.substr(1);
Edit
I didn't even think about it the first time, but you should refer to window.location, not document.location. It has the broadest browser support.
Peter Bailey
2009-04-18 06:55:38
Indeed the best solution. Mine was unnecessarily complicated, so I have deleted my answer.
Cerebrus
2009-04-18 06:59:42
String.substr is deprecated, instead use String.substring or String.slice
J-P
2009-04-18 12:24:29
It is? Don't see a mention here https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String/substr or here http://devedge-temp.mozilla.org/library/manuals/2000/javascript/1.5/guide/obj.html#1008731Where can I find this info?
Peter Bailey
2009-04-18 18:50:34
Is it a given (and compatible amongst all modern browsers) that location.search will begin with a question mark?
eyelidlessness
2009-04-20 08:02:56
A:
Hi all, i have
<script language="javascript">
document.write("<a href='http://www.gfi.com/downloads/downloads.aspx?pid=fax&lid=en" + document.location.search + "'><img src='http://images.gfi.com/download-imagery/button- download.png' border='0'></a>");
</script>
I want to replace the ? with &... How i can do that please?
Rene Zammit
2010-10-18 08:35:57