javascript - How to get a specific parameter in an url and add that to another url in Chrome Extension? -


only learnt coding 2 weeks sorry noob questions!

i trying build chrome extension runs following when click button on popup.html:

  1. gets , reads urls of each tab 1 one
  2. if url starts "https://www.linkedin.com/company/", gets company id right after "company/". (the url looks this: https://www.linkedin.com/company/164233?trk=prof-exp-company-name in case example, "164233") should create new tab following url: https://www.linkedin.com/vsearch/p?f_cc=164233

so far here codes have button:

document.addeventlistener('domcontentloaded', function (){     document.getelementbyid('btn2').addeventlistener('click', loadseeallemployees); });  function loadseeallemployees(e){     chrome.tabs.query({'active': true, 'lastfocusedwindow': true, 'currentwindow': true}, function (tabs) {     (i=0; i<chrome.tabs.getallinwindow().length; i++){         if(tabs.url.indexof("https://www.linkedin.com/company/")){          }     } };  } 

so name of button 'btn2' , function 'loadseeallemployees'

i stuck here because don't know how specific parameter , how can add url.

thank in advance.

string.prototype.slice()

mdn

the slice method extracts section of string , returns new string.


if not misunderstanding question, using slice function need, assuming url format consistent.

this isn't reliable method, but:

var query = tabs[0].url; var companyid = query.slice(32, 38);