추가 기능 SDK를 사용하여 탭 스타일을 동적으로 변경하려고합니다. 어떻게해야합니까? 여기 추가 기능 SDK를 사용하여 탭 스타일 변경
내가 시도 내용은 다음과 같습니다내가 같은 탭 개체에 액세스 할 수 있습니다 그래서
tab.setAttribute('style','background-color:blue'); // the method doesn't exist
tab.style.backgroundColor='blue'; // type error because style is null
tab.style='background-color:blue'; // has no effect
:
var tabs=require('sdk/tabs');
tabs.on('ready',function(tab){
console.log('url is: '+tab.url); //-> url is http://www.google.com
console.log('stlye is: '+tab.url); //-> style is null
});
을하지만 스타일 속성이 null
이며 다음 작업 없음 탭의 스타일을 어떻게 동적으로 바꿀 수 있습니까?
var { modelFor } = require("sdk/model/core");
var { viewFor } = require("sdk/view/core");
var tabs = require("sdk/tabs");
var tab_utils = require("sdk/tabs/utils");
function mapHighLevelToLowLevel(tab) {
// get the XUL tab that corresponds to this high-level tab
var lowLevelTab = viewFor(tab);
// now we can, for example, access the tab's content directly
var browser = tab_utils.getBrowserForTab(lowLevelTab);
console.log(browser.contentDocument.body.innerHTML);
// get the high-level tab back from the XUL tab
var highLevelTab = modelFor(lowLevelTab);
console.log(highLevelTab.url);
}
tabs.on("ready", mapHighLevelToLowLevel);
을하지만 코드는 오류가 발생합니다 : 내가 시도 또 한가지 code from the docs 사용하여 XUL 객체에 탭을 변환됩니다 이 모듈 'SDK/모델/코어'자원에서 발견되지 : // GRE/모듈 /commonjs/sdk/model/core.js 안내를 따라 core.js 파일을 만들었지 만. 또한 var { modelFor}=
구문에서 중괄호가 무엇을하는지 이해할 수 없습니다.
도움 주셔서 감사합니다.
감사합니다! 정말 당신의 도움을 주셔서 감사합니다 곧 솔루션을 다할 것입니다. 당신은'const를 설명 할 수 {getMostRecentBrowserWindow} ='구문? 무엇 중괄호는 무엇입니까? ES6 구조가 해제 되었습니까? –
'const'는 그 줄 다음에 바꿀 수없는'var'입니다. 예를 들어 curly와 equals는 "find' g etMostRecentBrowserWindow'를'require ('sdk/window/utils')의 객체에 넣고 그것을 여러분의 범위,'const' 또는'var'에 가져옵니다. 오브젝트에'getMostRecentWindow'가 존재하지 않는 경우는 동작하지 않습니다. – Noitidart
두 번째 코드 블록은 매력처럼 작동했습니다. 첫 번째는'htmlWindow'가 정의되지 않았기 때문에 작동하지 않았지만 오해했을 수도 있습니다. 이것은 대단합니다! 고맙습니다. –