How do i work around Slash in Chrome extension?
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"
精彩评论