Как передать URL активной вкладки в popup
Доброе утро!
Хочу передать URL активной вкладки из content script.js в popup.html Помогите! |
Ура! Нашел решение.
content_scripts.js var urlTab; urlTab = window.location.href; //Отправка информации в popup.js chrome.runtime.sendMessage({greeting: "hello", data:urlTab }, function(response) { console.log(response.farewell); }); popup.js document.addEventListener("click", function() { chrome.tabs.executeScript(null, { file: "/content_scripts/content_scripts.js" }); }); //вставка URL из браузера chrome.runtime.onMessage.addListener( function(request, sender, sendResponse) { console.log(sender.tab ? "from a content script:" + sender.tab.url : "from the extension"); if (request.greeting == "hello"){ var input = document.getElementById("Url"); input.value = request.data; sendResponse({farewell: "goodbye"}); }; }); |
Часовой пояс GMT +3, время: 05:58. |