您好我正在使用pdftron webviewer.js.創建色度應用程序。我能夠在瀏覽器上渲染pdf。但是當我在我的Chrome應用程序中包含pdftron webviewer庫時,I我得到一些錯誤。這是網絡版pdftron webviewer控件。document.write()和localStorage在chromeApp中不可用
我收到此錯誤: 1)document.write()的和localStorage的是不是打包應用程序可用。拋出新的錯誤(消息);
您好我正在使用pdftron webviewer.js.創建色度應用程序。我能夠在瀏覽器上渲染pdf。但是當我在我的Chrome應用程序中包含pdftron webviewer庫時,I我得到一些錯誤。這是網絡版pdftron webviewer控件。document.write()和localStorage在chromeApp中不可用
我收到此錯誤: 1)document.write()的和localStorage的是不是打包應用程序可用。拋出新的錯誤(消息);
document.write()
和localStorage
是not available in Chrome apps。
就這麼簡單。您需要使用不依賴這些庫的庫。
而不是重寫index.js文件中的window.localStorage,您可以更改lib/HTML5/ControlUtils.js以更改_storePreference和_getPreference函數的工作方式。而不是讓它們使用localStorage的(這是不提供的Chrome應用),你可以使用谷歌的存儲API https://developer.chrome.com/extensions/storage即
_storePreference: function(key, value) {
chrome.storage.local.set({key: JSON.stringify(value)});
}
如果你願意,你可以覆蓋這些功能在您的config.js文件即
window.ControlUtils.userPreferences._storePreference = function(key, value) {
chrome.storage.local.set({key: JSON.stringify(value)});
}
相反的document.write
你應該使用document.createElement
這是行不通的,因爲'chrome.storage.local'不是一個下拉更換localStorage'的'。它是異步的,而'localStorage'是同步的。 – Xan
根據OP,還有一個'document.write()'問題。 – Xan
謝謝Xan&Ryan,我爲此創建了一個示例,我得到兩個像localStorage和document.write()這樣的錯誤。我們可以解決這個問題嗎?這是我的示例: - https://jumpshare.com/v/LVWrorMVVkJJB7XvcidN –