Skip to Content
Menu
This question has been flagged

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
Discard
Author

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();
},
});
});

Related Posts Replies Views Activity
2
Dec 22
1525
2
May 22
11941
2
Apr 22
2795
1
Apr 22
2019
1
Nov 19
17306