How to set success message from JavaScript?

I use the following code to set the success message

if (data.success) {
		<?php page()->setSuccessMessage("Created Successfully.") ?>
		window.location.href = "login";
	  } else {
        showError(el.newpin, data.message || "Failed to create.");
      }

The code is working correctly but I want to know that is there any built in js function to set the success message from the javascript without using the php code inside the javascript.

You may simply use:

ew.alert("Your success message goes here ...", "success");

when I use
ew.alert("Your success message goes here ...", "success");
It popup a message for few 1 or 2 seconds and redirected to the login page as I am using
window.location.href = "login";

but I want same work flow of the
page()->setSuccessMessage("Created Successfully.")
as this will display the message in the login page.

Then for such case you have to use Page_Load server event that belongs to the Login page.