开发者

Get Unique Email Identifier from GMail URL

开发者 https://www.devze.com 2023-01-10 21:26 出处:网络
At the moment, I am coding an Google Chrome extension (in Javascript) which interfaces开发者_如何学Go with GMail. The extension needs to know the unique email identifier that is present at the end of

At the moment, I am coding an Google Chrome extension (in Javascript) which interfaces开发者_如何学Go with GMail. The extension needs to know the unique email identifier that is present at the end of every GMail URL.

Eg. https://mail.google.com/mail/#inbox/11a4ac0cg2bc3330 https://mail.google.com/mail/#label/Archived+Emails/11a4c8b472b03c87

What would be the best way to get this unique identifier using Javascript (through regex or otherwise, preferably in a function like this:

function getIdentifier(URL){ [Insert your magic here] return ID; }

Thanks,

DLiKS


this is based on your samples provided, if you're assured of the format, you can use .substirng() and .lastIndexOf(), like this:

function getIdentifier(URL){
  return URL.substring(URL.lastIndexOf('/') + 1);
}

You can give it a try here, this keeps it pretty simple, find the last /, move over one to exclude the / itself, take the rest of the string.

0

精彩评论

暂无评论...
验证码 换一张
取 消