webview-custom-zoom-level.html 793 B

123456789101112131415161718192021222324252627
  1. <html>
  2. <body>
  3. <webview nodeintegration src="zoom://host1" id="view" partition="webview-temp"/>
  4. </body>
  5. <script>
  6. const {ipcRenderer, webFrame} = require('electron')
  7. const view = document.getElementById('view')
  8. let finalNavigation = false
  9. view.addEventListener('dom-ready', () => {
  10. if (!finalNavigation && !view.canGoBack()) {
  11. view.setZoomLevel(2.0)
  12. }
  13. view.getZoomLevel((zoomLevel) => {
  14. view.getZoomFactor((zoomFactor) => {
  15. ipcRenderer.send('webview-zoom-level', zoomLevel, zoomFactor, view.canGoBack(), finalNavigation)
  16. if (!view.canGoBack() && !finalNavigation) {
  17. view.src = 'zoom://host2'
  18. } else if (!finalNavigation) {
  19. finalNavigation = true
  20. view.goBack()
  21. }
  22. })
  23. })
  24. })
  25. </script>
  26. </html>