Ir al contenido
Menú
Se marcó esta pregunta
3920 Vistas

Why 'window.addEventListener("hashchange",...' or 'window.onhashchange' JS events are not working on odoo15 backend? Whereas they are working fine until odoo14. What has changed? Or any other workaround for this event? I am not able to capture the changes of hash values of URLs while traversing in the backend in odoo 15 only. They are working fine in odoo 13,14 etc.

Avatar
Descartar
Autor

In Odoo 15, the backend URL structure has changed, so the hashchange event is no longer triggered when navigating between pages. This is because the URL now uses a route system rather than hashes to indicate the current page.

To detect changes in the current route, you can use the odoo.__DEBUG__.services['web_tour.tour'].router.current_route variable in your JavaScript code. You can listen for changes to this variable and perform any necessary actions when it is updated.

Alternatively, you can use the web_tour.tour service to listen for route changes and trigger your custom code. Here is an example:

odoo.define('my_module.route_listener', function (require) {
'use strict';

var Tour = require('web_tour.tour');

Tour.register({
id: 'my_route_listener',
name: 'My route listener',
path: '/web', // or any other route you want to listen to
mode: 'test',
onChange: function (page, next) {
// your custom code here
// `page` is the current route
next();
},
});
});

Publicaciones relacionadas Respuestas Vistas Actividad
2
dic 22
2516
2
may 22
13794
2
abr 22
4003
1
abr 22
3071
1
nov 19
18419