正在尝试从选项卡中检索当前URL。我们的目标是能够点击这个扩展,它会自动拉取当前chrome表的域的搜索信息。尝试使用此搜索url将当前正在访问的任何"www.apple.com“选项卡窗口url拉入扩展中,以获取公司信息。
这就是我所拥有的: popup.html
<head>
<title>
Chrome Extension
</title>
<script src="offline.js"></script>
</head>
<body>
<iframe src="https://www.owler.com/iaApp/browsecompanyprofiles.htm?searchTerm=$activeTab” oncontextmenu="return false;">
ERROR, can't load content
</iframe>
<script>
chrome.tabs.query({active: true, currentWindow: true}, function(arrayOfTabs) {
var activeTab = arrayOfTabs[0];
var activeTabId = activeTab.id;
});
function getCookie(cname)
{
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++)
{
var c = ca[i];
while (c.charAt(0) == ' ')
{
c = c.substring(1);
}
if (c.indexOf(name) == 0)
{
return c.substring(name.length, c.length);
}
}
return "";
}
if(getCookie('hostinger')) {
document.cookie = 'hostinger=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';location.reload();
}
var notification = document.getElementsByClassName('notice notice-success is-dismissible');
if(notification.length > 0) {
notification = notification[0];
notification.setAttribute('style', "padding-bottom: 10px; padding-top: 5px; background-image: url(https://cdn.rawgit.com/hostinger/banners/master/hostinger-bf-bg.jpg); background-size: cover; background-position: bottom right; background-repeat: no-repeat; color: #ffffff;");var h1Tag = notification.getElementsByTagName("H1")[0];h1Tag.setAttribute('style', "color:#f15f5f;font-weight:700;");h1Tag.innerHTML = "Get 90% Discount for Premium Web Hosting";var link = notification.getElementsByTagName("P")[0].getElementsByTagName('A')[0];link.setAttribute('style', "color:#f15f5f");var list = notification.getElementsByTagName("UL")[0];var listElements = list.getElementsByTagName("LI");for (var i = 0; i < listElements.length; i++) {listElements[i].setAttribute('style', "color:#ffffff");}}
<iframe src="https://www.owler.com/iaApp/browsecompanyprofiles.htm?searchTerm=$activeTab” oncontextmenu="return false;">
ERROR, can't load content
</iframe>
</script></body>
</html>
<style>
html, body{
margin: 0px;
padding: 0px;
}
iframe{
width: 400px;
height: 600px;
border: none;
}
</style>发布于 2017-12-05 15:02:42
window.location.href将为您提供当前选项卡的url
https://stackoverflow.com/questions/47647728
复制相似问题