2013-02-15 48 views
1

我正在寫一個Chrome擴展,其中有一個彈出窗口。當用戶身份驗證失敗時,彈出窗口會顯示通知,指出登錄失敗,並且希望在該通知中包含指向我的擴展程序選項頁的鏈接。在Chrome擴展彈出窗口中使用__MSG _ @@ extension_id__與jQuery創建鏈接

function notifyHTML(html) { 
    $("#notification_bar").html(html); 
    $("#cont").fadeIn(30).delay(3000).fadeOut(300); //notify  
} 
function onLoginFailed() { 
    console.log("From extension: Login failed. Check username-password"); 
    notifyHTML("Login Failed. Update in <a href=\"chrome-extension://[email protected]@extension_id__/html/options.html\">Options</a> page"); 
} 

相關HTML:

<div> 
      <div id="cont"><div id="notification_bar"></div></div> 
      <!-- More HTML --> 
</div> 

但這樣做導致該通知的無效鏈接,所以我在彈出的窗口中的javascript文件這樣做。如何解決這個問題?

回答

2

使用下面的代碼

function onLoginFailed() { 
    console.log("From extension: Login failed. Check username-password"); 
    retStr = "Login Failed. Update in <a href=\"chrome-extension://" + chrome.i18n.getMessage("@@extension_id") + "/html/options.html\">Options</a> page"; 
    notifyHTML(retStr); 
} 

您應該使用chrome.i18n.getMessage() API使用任何預定義的消息。

參考

0

更好的選擇是使用chrome.extension.getURL

function onLoginFailed() { 
    console.log("From extension: Login failed. Check username-password"); 
    notifyHTML('Login Failed. Update in <a href="' + chrome.extension.getURL("/html/options.html") + '">Options</a> page'); 
} 

http://developer.chrome.com/extensions/extension#method-getURL

相關問題