I tried to use in in Global > Page Rendering event but I get error "Uncaught ReferenceError: loadjs is not defined"Please advise how to use alertify for all pages of the project. (v2024)
You should include your base path of your site like AddStylesheet(“/basepath/alertifyjs/…”) and AddClientScript(“/basepath/alertifyjs/…”). Make sure you put your “alertifyjs” folder under the root folder of the project folder. Replace “basepath” by your real base path.
Page_Rendering is not for outputting HTML. If you use that, you output HTML earlier than everything else so loadjs is not ready yet.
You can use Page_DataRendering but you should add the HTML to the $header argument, not echoing HTML directly.
If you use AddClientScript(), note that the script is also loaded by loadjs, you need to wait until it is loaded before using it, so you better add an id, e.g.
Thank you but the code is working for separate pages of the project.
But now I need to make working it for all pages of the project. In order not to copy-paste same code to all pages of the project (in Page Data Rendering event).Is it possible to use a Global code and how?
In order not to copy-paste same code to all pages of the project (in Page Data Rendering event).
Why is it necessary? You use alertify only at where you need to use it, e.g. when you have an error to show. Usually the page is already loaded at that time, you may use it directly, you don’t need to always use loadjs.ready().Note that Page_Head is for all pages, you have added alertify to all pages.
You may Create Your Own API Action, call it when you need the information and alert user if necessary. In fact, unless you like alertify, otherwise you may simply use the built-in alert by SweetAlert2, e.g. ew.alert(“my message”).