I get links. They may be different, but you need to get that part of the characters from the link that comes after the question mark. I tried to remove extra characters before the question mark, but the problem is that the link length is different each time ...
How can I solve this problem?
|
3 answers
var link = "lalala?tatata" var string = link.split("?")[1]; //tatata |
var str = window.location.search; If from the current URL
|
Well, for example, more regular:
var query = url.replace(/.*\?/, ""); Possible and cycle
var startQueryIndex = null; var len = url.length; for(var i = 0; i < len; i++) { if(url[i] == "?") { startQueryIndex = i; break; } } var query = url.substr(startQueryIndex); // вернет вместе с ?, если без него то (startQueryIndex + 1) - Regulars for such a simple task are like an excavator for a sandbox. In addition, if you know about the existence of split () and regulars, it should be a shame to suggest using the cycle - P. Ilyin
- @ P.Ilyin, you may notice that I have the most recent answer, so it only complements the previous ones. And to duplicate their code to anything - ThisMan
|