Write script for form cancel button for both add and edit records

Write script for form cancel button for both add and edit records

I want to load the edit record using edit url when i click the cancel button i want to redirect some other. is it possible to write code for form cancel action for add / edit record