2012-08-29 2 views
1

this.window.location.href 크롬 확장에 작동하지 window.location.href :내가 스크립트에서이 기능을 시도 HTML 파일에서 크롬 확장 작동하지 않습니다

function myFunction() 
{ 
    var pl = this.window.location.href; 
    var sWords= localStorage.getItem(pl); 
    document.write(pl); 
} 

을 그리고 그것은 나에게 제공합니다

chrome-extension://ebeadbfnnghmakkbimckpdmocjffkbjc/popup.html 

페이지의 링크를 얻으려면 어떻게해야합니까?

+0

의 중복 가능성 [내 페이지 액션 팝업에서 현재 열려있는 탭의 URL을 얻는 방법?] (http://stackoverflow.com/questions/10413911/how-to-get-the-currently -opened-tabs-url-in-my-page-action-popup) –

+0

@RobW 링크 제거 .. 포인터 주셔서 감사합니다 ... 미안 ... – ManseUK

답변

2

chrome.tabs.query 방법을 통해 현재 선택된 탭을 가져올 수 있습니다. 당신은 두 가지 옵션을 전달해야

  1. currentWindow : true
  2. active : true

그것은 기준과 일치 탭의 배열을 반환합니다. 거기에서 URL을 얻을 수 있습니다. 이처럼 :

chrome.tabs.query(
    { 
     currentWindow: true, // currently focused window 
     active: true   // selected tab 
    }, 
    function (foundTabs) { 
     if (foundTabs.length > 0) { 
      var url = foundTabs[0].url; // <--- this is what you are looking for 
     } else { 
      // there's no window or no selected tab 
     } 
    } 
); 
관련 문제