最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get param value after hash in URL in vanilla JS - Stack Overflow

programmeradmin0浏览0评论

I know this is probably extremely simple, but I can't seem to figure it out or find the answer I'm looking for. I'm using Instagram's API to allow user's to login and see their feed. This is done on the client side with Javascript. After authorizing my app, the browser sends back an access token in the url like so: www.example/#access_token=12345679.

What's the simpest vanilla JS to get the raw number of the access token? I've tried location.hash but that returns both the key and value like so: acess_token=123456789

Any help appreciated.

I know this is probably extremely simple, but I can't seem to figure it out or find the answer I'm looking for. I'm using Instagram's API to allow user's to login and see their feed. This is done on the client side with Javascript. After authorizing my app, the browser sends back an access token in the url like so: www.example./#access_token=12345679.

What's the simpest vanilla JS to get the raw number of the access token? I've tried location.hash but that returns both the key and value like so: acess_token=123456789

Any help appreciated.

Share Improve this question edited Dec 9, 2013 at 22:54 linstantnoodles 4,4001 gold badge24 silver badges24 bronze badges asked Dec 9, 2013 at 22:35 Sean ThompsonSean Thompson 9021 gold badge9 silver badges19 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

Assuming the hash pattern is consistent, you can get the access_token value with the following code:

var hash = window.location.hash;
var accessToken = hash.split('=')[1];

Just split with '=' on the returned key value pair

var token = obj.split('=')[1] ;
发布评论

评论列表(0)

  1. 暂无评论