When I open a reader enabled form and close it without doing anything it prompts "Do you want save changes to <filename> before closing?". How to get rid of this? I tried the below code in the layout ready event of a button but still no effect.
Any solution is greatly appreciated. Many thanks in advance.
The script you already use
is the only way to avoid that.
If it doesn't work, then because of any other script, that is executed also in the layoutReady event that causes to change the dirty flag back to true.
The script that is used is for the page numbering (the page n of m element in the livecycle designer). Also script to display/hide a field based on some selection when the form is reopened.
The show/hide script in the layoutReady event is the problem as it dirties the form permanently.
You should use another event to control the visiblity, like the change event.