Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to revert to windows if JS value is null

I have like no JS experience, but I need help.

So I have a code that allows a user to manually enter a URL.

Well, If they leave the value blank and click out it "NULLS". I want a way to detect that null and revert back to "/" or the same page instead of /null

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

function url(){
    swal("Enter a URL:", {
        content: "input",
      })
      .then((value) => {
        location.replace(value);
        
      });
}
// PROD Fix, needs a zero-null failure-fix. Find a way to prevent zero-data/null.

>Solution :

You can add a test for the null value before the location.replace() and change the value to the url you want as default.

function url(){
    swal("Enter a URL:", {
        content: "input",
      })
      .then((value) => {
        if (value === null) value = "your replacement url";
        location.replace(value);
        
      });
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading