diff --git a/addons/website/static/src/client_actions/website_preview/website_preview.js b/addons/website/static/src/client_actions/website_preview/website_preview.js index 86e6194e049..620f8931efe 100644 --- a/addons/website/static/src/client_actions/website_preview/website_preview.js +++ b/addons/website/static/src/client_actions/website_preview/website_preview.js @@ -94,6 +94,32 @@ export class WebsitePreview extends Component { this.websiteService.pageDocument = null; }); + /** + * This removes the 'Odoo' prefix of the title service to display + * cleanly the frontend's document title (see _replaceBrowserUrl), and + * replaces the backend favicon with the frontend's one. + * These changes are reverted when the component is unmounted. + */ + useEffect(() => { + const backendIconEl = document.querySelector("link[rel~='icon']"); + // Save initial backend values. + const backendIconHref = backendIconEl.href; + const { zopenerp } = this.title.getParts(); + this.iframe.el.addEventListener('load', () => { + // Replace backend values with frontend's ones. + this.title.setParts({ zopenerp: null }); + const frontendIconEl = this.iframe.el.contentDocument.querySelector("link[rel~='icon']"); + if (frontendIconEl) { + backendIconEl.href = frontendIconEl.href; + } + }, { once: true }); + return () => { + // Restore backend initial values when leaving. + this.title.setParts({ zopenerp, action: null }); + backendIconEl.href = backendIconHref; + }; + }, () => []); + useEffect(() => { // When reaching a "regular" url of the webclient's router, an // hashchange event should be dispatched to properly display the diff --git a/addons/website/static/src/components/dialog/seo.js b/addons/website/static/src/components/dialog/seo.js index 26489d92ca0..9fe1463031f 100644 --- a/addons/website/static/src/components/dialog/seo.js +++ b/addons/website/static/src/components/dialog/seo.js @@ -4,7 +4,7 @@ import { useService, useAutofocus } from '@web/core/utils/hooks'; import { MediaDialog } from '@web_editor/components/media_dialog/media_dialog'; import { WebsiteDialog } from './dialog'; -const { Component, useState, reactive, onMounted, onWillStart } = owl; +const { Component, useState, reactive, onMounted, onWillStart, useEffect } = owl; // This replaces \b, because accents(e.g. à, é) are not seen as word boundaries. // Javascript \b is not unicode aware, and words beginning or ending by accents won't match \b @@ -267,6 +267,17 @@ class TitleDescription extends Component { this.maxRecommendedDescriptionSize = 300; this.minRecommendedDescriptionSize = 50; + + // Update the title when its input value changes + useEffect(() => { + document.title = this.title; + }, () => [this.seoContext.title]); + + // Restore the original title when unmounting the component + useEffect(() => { + const initialTitle = document.title; + return () => document.title = initialTitle; + }, () => []); } get seoNameUrl() {