I am trying to create a very simple chrome extension that open multiple tabs of LinkedIn searching different keywords that I type in.
Since this is my first extension, most of my codes are based on this extension, which is very similar to my idea.
The problem is when I click my "search" button, nothing happens. I just started coding for a week so I'd greatly appreciate any help!
Besides knowing what is wrong with the codes, is a background script necessary in this case?
Thanks!
Here are my codes:
Manifest.json
{ "manifest_version": 2, "name": "Search Assistant", "description": "This extension makes LinkedIn Search easy.", "version": "1.0", "browser_action": { "default_icon": "icon.png", "default_popup": "popup.html" }, "content_scripts": [ { "matches": ["http://*/*", "https://*/*"], "js": ["myscript.js"] } ], "chrome_url_overrides" : { "newtab": "newtab.html" }, "background": { "scripts": ["bg.js"] } } Popup.html
<!doctype html> <head> <style type="text/css"> body{ font family: Helvetica, Arial, sans; font-size: 12px; } #instruction{ padding-bottom: 10px; } #searcharea{ padding-bottom: 10px; } #search{ padding-bottom: 10px; float: left; } #companies{ white-space: nowrap; overflow:auto; } </style> <style type="text/javascript" src="popup.js"></style> </head> <body> <div id="instruction">Companies you want to search for:</div> <div id="searcharea"><textarea rows="20" cols="80" id="companies" wrap="soft" tabindex="1"></textarea></div> <div id="search"> <button id="btn1" tabindex="2">Search</button> </div> <p id="demo"></p> </body> </html> Popup.js
document.addEventListener('DOMContentLoaded', function (){ document.getElementById('btn1').addEventListener('click', loadSites); document.getElementById('companies').focus(); }); function loadSites(e){ var companies = document.getElementById('companies').value.split('\n'); for(var i=0; i<companies.length; i++){ thecompany = companies[i].trim(); thesearchurl = 'https://www.linkedin.com/vsearch/c?type=companies&keywords=' + thecompany; chrome.extension.create({url: thesearchurl, selected:false}) } }