2017-11-16 2 views
0

크롬 확장 기능을 개발 중입니다.크롬 확장에서 스크립트 사이에 전역 변수 설정

windows.open ("website_number_1.html"); 내 웹 사이트에서

나는를했습니다

그런 다음 내 manifest.json을은 다음과 같습니다 website_number_1.html)는 (은 window.open에서 열릴 경우에만

는 것은이
"content_scripts": [ 
     { 
     "matches": ["website_number_1.html"], 
     "js": ["script1.js"] 

     }, 

, 난 script1.js을 실행하려면; . 그래서 나는 window.open 바로 다음에 전역 변수를 선언 할 생각을했습니다.

global var launch = "yes"; script1.js에서

다음 : 사전에 대단히

if launch == "yes"{ 
    my_script 
} 
else{ 
    //do nothing 
} 

감사합니다. 의 manifest.json 건배

+0

변수는 내 나쁜 영어 죄송 당 프레임 의미 :

나는이 :)

PS 좋다고 생각합니다. – wOxxOm

답변

0

Script1.js에서
"permissions": [ 
"tabs" 
], 

$(document).ready(function(){ 
chrome.tabs.getSelected(null,function(tab){ 
    var link = document.createElement('a'); 
    link.href = tab.url; 
    var host = link.hostname; 

    var valid_url = "valid url page"; 

    if(host == valid_url){ 
     //Code 
    }else{ 
     //This is element in HTML of course you can make other function 
     $("#host").html("This Page is not correct "); 
    } 

}) 

}); 다른 창은 컨텍스트를 공유하지 않습니다