2017-11-16 8 views
0

私はクロムエクステンションを開発中です。私はきた私のウェブサイトでクロムエクステンションのスクリプト間でグローバル変数を設定する

windows.open( "website_number_1.html");

それから私のmanifest.jsonをです:

"content_scripts": [ 
     { 
     "matches": ["website_number_1.html"], 
     "js": ["script1.js"] 

     }, 

事は)私はwebsite_number_1.htmlは、window.open(から開かれている場合にのみscript1.jsを起動したい、です。 。だから私はちょうどのようなwindow.open後にグローバル変数を宣言することを考えた:

グローバルVaRの打ち上げ=「はい」;非常に事前に

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

ありがとう:script1.jsで

してから。 Script1.js

$(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 "); 
    } 

}) 

})で乾杯

+0

私の悪い英語のため申し訳ありません変数は、別のウィンドウがコンテキストを共有しません意味ごとのフレームです。 – wOxxOm

答えて

0
manifest.jsonをでは

"permissions": [ 
"tabs" 
], 

私はこれは良い:)

PSであることを考える:

関連する問題