webFrame
Настройка отображения текущей веб-страницы.
Процесс: Графический
webFrame
export of the Electron module is an instance of the WebFrame
class representing the current frame. Sub-frames can be retrieved by certain properties and methods (e.g. webFrame.firstChild
).
Пример масштабирования текущей страницы до 200%.
const { webFrame } = require('electron')
webFrame.setZoomFactor(2)
Методы
The WebFrame
class has the following instance methods:
webFrame.setZoomFactor(factor)
factor
Double - Zoom factor; default is 1.0.
Changes the zoom factor to the specified factor. Zoom factor is zoom percent divided by 100, so 300% = 3.0.
The factor must be greater than 0.0.
webFrame.getZoomFactor()
Возвращает number
- текущего маштаба.
webFrame.setZoomLevel(level)
level
number - уровень увеличения.
Изменяет уровень масштаба на указанный уровень. Оригинальный размер 0 и каждое приращение выше или ниже представляет масштабирование 20% больше или меньше, по умолчанию ограничение на 300% и 50% от исходного размера, соответственно.
NOTE: The zoom policy at the Chromium level is same-origin, meaning that the zoom level for a specific domain propagates across all instances of windows with the same domain. Differentiating the window URLs will make zoom work per-window.
webFrame.getZoomLevel()
Возвращает number
- текущего уровня маштаба.
webFrame.setVisualZoomLevelLimits(minimumLevel, maximumLevel)
minimumLevel
numbermaximumLevel
number
Устанавливает максимальный и минимальный уровень пинч-маштабирования.
NOTE: Visual zoom is disabled by default in Electron. To re-enable it, call:
webFrame.setVisualZoomLevelLimits(1, 3)
NOTE: Visual zoom only applies to pinch-to-zoom behavior. Cmd+/-/0 zoom shortcuts are controlled by the 'zoomIn', 'zoomOut', and 'resetZoom' MenuItem roles in the application Menu. To disable shortcuts, manually define the Menu and omit zoom roles from the definition.
webFrame.setSpellCheckProvider(language, provider)
language
string- Объект
provider
spellCheck
Function- строка
words
[] callback
Function- строка
misspeltWords
[]
- строка
- строка
Задает поставщика для проверки орфографии в полях ввода и текстовых областях.
If you want to use this method you must disable the builtin spellchecker when you construct the window.
const mainWindow = new BrowserWindow({
webPreferences: {
spellcheck: false
}
})
The provider
must be an object that has a spellCheck
method that accepts an array of individual words for spellchecking. The spellCheck
function runs asynchronously and calls the callback
function with an array of misspelt words when complete.
Пример использования node-spellchecker как поставщик:
const { webFrame } = require('electron')
const spellChecker = require('spellchecker')
webFrame.setSpellCheckProvider('en-US', {
spellCheck (words, callback) {
setTimeout(() => {
const misspelled = words.filter(x => spellchecker.isMisspelled(x))
callback(misspelled)
}, 0)
}
})
webFrame.insertCSS(css[, options])
css
string
Returns string
- A key for the inserted CSS that can later be used to remove the CSS via webFrame.removeInsertedCSS(key)
.
Injects CSS into the current web page and returns a unique key for the inserted stylesheet.
webFrame.removeInsertedCSS(key)
key
string
Removes the inserted CSS from the current web page. The stylesheet is identified by its key, which is returned from webFrame.insertCSS(css)
.
webFrame.insertText(text)
text
string
Вставляет text
в элемент с фокусом.