jQuery Event for changing page

Hello there,

is there any jQuery Event I can listen to, to do something when a user clicks somewhere and comes to another “place”?

Example:

I want to add a button to . layout-side-section, but I need to listen to a event, every time this part of the page is loaded.

Thank you very much.

EDIT: It should be working for all Frappe/ERPNext, not for a single doctype. So I want to write it to my .js-File, which is included like this:

app_include_js = “/assets/js/myapp.js”

Any ideas?

@ci2016

No need to use Jquery. use, frappe.set_route()

For Page

frappe.set_route("page-name")`
  • For particular form

    frappe.set_route(“Form”, “Doctype”, “Docname”)

  • For Listview

    frappe.set_route(“List”, “Doctype”)`

@Sangram Thank you for that. Maybe my question wasn’t clear. I wan’t a callback event to listen on, when a user changes the page or clicks on an app.

I already tried Mutation Observer, what it fires several times in the wrong moment.

EDIT: I found the following event, which is pretty much, what I was asking for:

$(document).on('page-change', function(e) {
	console.log("do something");
});

EDIT: Post can be closed.

1 Like