JavaScript从URL抓取OAuth令牌?

JavaScript从URL抓取OAuth令牌?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我正在使用一个隐式使用OAuth的API。它重定向到URL 我如何通过JavaScript获取这些信息? 谢谢您可以使用window.location.hash 要从url获取令牌,请使用以下代码: <script type="text/javascript"> hash = window.location.hash.substr(1); //url of the current page arHash = hash.split('='); //this create

我正在使用一个隐式使用OAuth的API。它重定向到URL

我如何通过JavaScript获取这些信息?
谢谢

您可以使用
window.location.hash

要从url获取令牌,请使用以下代码:

<script type="text/javascript">
    hash = window.location.hash.substr(1); //url of the current page
    arHash = hash.split('='); //this creates an array with key ([0] element) and value ([1] element)
    hash_value =  arHash[1]; //recieve value
</script>

hash=window.location.hash.substr(1)//当前页面的url
arHash=hash.split('=')//这将创建一个包含键([0]元素)和值([1]元素)的数组
hash_value=arHash[1]//接收值