javascript - Remove unwanted text from link using jquery -
hello friends want make function remove specific group of words input link before doing search :
i got coding :
jquery :
<script type="text/javascript"> function getidinfo() { var q = document.getelementbyid("graph").value; window.open("http://graph.facebook.com/" + q,"", "width=500px, height=300px"); } </script>
html :
<form action="index.php" method="get"> <input id="graph" type="text" name="q" size="20" placeholder="guru.of.fun or 100xxxx"/></td> <input type="button" name="graph" value="get facebook data" class="submit" onclick="getidinfo()" />
and want remove https://graph.facebook.com/
, read text after slash /
for example :
100008622 full link https://www.facebook.com/100008622
- if user enter in search text area..
you can use .split().pop()
:
var url = document.getelementbyid("graph").value; var value = url.split('/').pop();
here .split()
makes array out of url , .pop()
returns last value in array.
you can see test here.
var url = 'https://www.facebook.com/100008622'; var value = url.split('/').pop(); alert(value)
Comments
Post a Comment