首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HTML Chrome扩展

HTML Chrome扩展
EN

Stack Overflow用户
提问于 2017-12-05 14:52:41
回答 1查看 46关注 0票数 0

正在尝试从选项卡中检索当前URL。我们的目标是能够点击这个扩展,它会自动拉取当前chrome表的域的搜索信息。尝试使用此搜索url将当前正在访问的任何"www.apple.com“选项卡窗口url拉入扩展中,以获取公司信息。

这就是我所拥有的: popup.html

代码语言:javascript
复制
    <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>
EN

回答 1

Stack Overflow用户

发布于 2017-12-05 15:02:42

window.location.href将为您提供当前选项卡的url

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47647728

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档