简体   繁体   中英

How can I copy a specific part of a URL to the clipboard with a Chrome extension?

I have been attempting to write a chrome extension that copies a specific part of a URL when a user right clicks on a hyper link.

For instance, I am interested in copying the 17 characters that appear to the right of "Flid%3D" that appears within a URL, to the clip board.

The clipboard API is still experimental. You can start writing your extension with it and test it if you set the experimental flag in about:flags (only possible on a dev build I think). You will have to wait to release your extension until the API is released.

Caution: Don't depend on these experimental APIs. They might disappear, and they will change. Also, the Chrome Developer Dashboard doesn't allow you to upload extensions that use experimental APIs.

EDIT

So this is actually a question about string manipulation? I guess you want to use regular expressions for this, perhaps something like /Flid%3D(.{17})/ . This searches for the first occurrence of the literal Flid%3D followed by the 17 characters. You would use it like this:

var myUrl = 'http://www.helloworld.com/Flid%3Dabcdefghijklmnopqrstuvw';
var match = myUrl.match(/Flid%3D(.{17})/);
if(match !== null) {
  // we found the part
  var part = match[1];
}

and the resulting string in part would be 'abcdefghijklmnopq' .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM