[英]How to get a specific parameter in an url and add that to another url in Chrome Extension?
Only learnt coding for 2 weeks so sorry for noob questions! 仅学习了2周的编码,因此对菜鸟提出的问题感到抱歉!
I am trying to build a chrome extension that runs the following when I click a button on popup.html: 我试图构建一个Chrome扩展程序,当我在popup.html上单击一个按钮时,该扩展程序将运行以下命令:
So far here are the codes I have for this 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) {
for (i=0; i<chrome.tabs.getAllInWindow().length; i++){
if(tabs.url.indexOf("https://www.linkedin.com/company/")){
}
}
};
}
So the name of the button is 'btn2' and the function is 'loadSeeAllEmployees' 因此,按钮的名称为“ btn2”,函数为“ loadSeeAllEmployees”
I am stuck here because I don't know how to get that specific parameter and how I can add it to another url. 我被困在这里是因为我不知道如何获取该特定参数以及如何将其添加到另一个URL。
Thank you in advance. 先感谢您。
The slice method extracts a section of a string and returns a new string. slice方法提取字符串的一部分并返回新的字符串。
This probably isn't the most reliable method, but: 这可能不是最可靠的方法,但是:
var query = tabs[0].url; var companyId = query.slice(32, 38);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.