Get current URL from within a chrome.contextMenus.onClicked listener

前端 未结 4 753
时光取名叫无心
时光取名叫无心 2021-02-06 09:36

I\'m creating my first Chrome extension and I need some help. I I think everything is working except the fact that I can\'t get the current URL of the tab.

var m         


        
4条回答
  •  离开以前
    2021-02-06 10:02

    If you are using content script you can use

    document.location.href
    

    document.location is Object and can provide set of useful chunks in the URL

    • document.location.host returns domain name ex: "http://www.google.com/"
    • document.location.path returns the part after the domain name
    • document.location.hash returns whatever after # symbol in the url

提交回复
热议问题