开发者

How do i work around Slash in Chrome extension?

开发者 https://www.devze.com 2023-03-21 14:46 出处:网络
In my extension i want to get href property of a object, which is /photo123456789_987654321. But instead i getchrome开发者_运维百科-extension://extension-id/photo123456789_987654321.

In my extension i want to get href property of a object, which is /photo123456789_987654321.

But instead i get chrome开发者_运维百科-extension://extension-id/photo123456789_987654321.

How do i work around this?


Instead of using a more-complicated regex you can just use the first part of the string:

http://jsfiddle.net/3qRQT/

var someString = "chrome-extension://extension-id/photo123456789_987654321";

someString.replace("chrome-extension://extension-id","");


What about replacing the extension id with a regexp:

href_string.replace(/^chrome-extension:\/\/.*?\//, "/");

E.g.

var href_string = "chrome-extension://extension-id/photo123456789_987654321";
href_string.replace(/^chrome-extension:\/\/.*?\//, "/");

// "/photo123456789_987654321"
0

精彩评论

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

关注公众号