Augustus
Augustus

Reputation: 45

How to make a js code which allows user to view their page only if they satisfy the 'if' condition?

This is the sample code:

var users = ["ownersName","Others"];
var name=prompt("Enter your name");
if(name==users[0]){
    w
    alert("Hey"+' '+name)
    alert("You have been granted the webMaster Role!")
}
else{
    console.log("hello user");
}

I want to allow the user to view the page only if his name satisfies 'ownersName'.

Upvotes: 2

Views: 39

Answers (1)

Mohammad Ali Rony
Mohammad Ali Rony

Reputation: 4915

You can redirect to blank URL about:blank or

document.documentElement.innerHTML='';

to restrict the user to view page

var users = ["ownersName","Others"];
var name=prompt("Enter your name");
if(name==users[0]){
    w
    alert("Hey"+' '+name)
    alert("You have been granted the webMaster Role!")
}
else{
   document.documentElement.innerHTML = '';
   //window.location = 'about:blank';
}

Upvotes: 2

Related Questions