webview-in-page-navigate.html 900 B

123456789101112131415161718192021222324252627282930313233
  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. function SendZoomLevel() {
  10. return new Promise((resolve, reject) => {
  11. view.getZoomLevel((zoomLevel) => {
  12. view.getZoomFactor((zoomFactor) => {
  13. ipcRenderer.send('webview-zoom-in-page', zoomLevel, zoomFactor, finalNavigation)
  14. resolve()
  15. })
  16. })
  17. })
  18. }
  19. view.addEventListener('dom-ready', () => {
  20. view.setZoomLevel(2.0)
  21. SendZoomLevel().then(() => {
  22. if (!finalNavigation) {
  23. finalNavigation = true
  24. view.executeJavaScript('window.location.hash=123', () => {})
  25. }
  26. })
  27. })
  28. view.addEventListener('did-navigate-in-page', () => {
  29. SendZoomLevel()
  30. })
  31. </script>
  32. </html>