how to get first argument from url in javascript - Stack Overflow

I just wanted to find my first argument from my url.like;sourceid=chrome&ie=UTF-8I just wanted to st


I just wanted to find my first argument from my url.

like

;sourceid=chrome&ie=UTF-8

I just wanted to string "ix=teb".

How to get that string only.


I just wanted to find my first argument from my url.

like

http://www.google.co.in/webhp?ix=teb&sourceid=chrome&ie=UTF-8

I just wanted to string "ix=teb".

How to get that string only.

Share Improve this question asked Mar 17, 2012 at 6:52 NitzNitz 1,72611 gold badges37 silver badges56 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6
window.location.search.replace("?", "").split("&")[0];

update:

in case there's a variable holding url:

url.substring(url.lastIndexOf("?") + 1).split("&")[0];

You can use a regular expression to read out parts of the URL:

window.location.search.match(/\?([^&$]+)/)[1] // == 'ix=teb'

In the event that there isn't anything in the query string of the URL, this would cause an error, so you should include some type checking like:

var queryStringMatch = window.location.search.match(/\?([^&$]+)/);
if(queryStringMatch) {
   // do something with queryStringMatch[1]
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742338986a4425235.html

相关推荐

  • how to get first argument from url in javascript - Stack Overflow

    I just wanted to find my first argument from my url.like;sourceid=chrome&ie=UTF-8I just wanted to st

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信