Verify user

Asked

Viewed 20 times

0

I want that when the user logs in to my page, javascript checks his profile on the system and if the profile is empty, it directs to the home page.

It’s simple, I’m trying this code here, but it’s not working right:

<script>

  var perfil = document.querySelector('#perfil').textContent;

  if (perfil = ''){

  window.location = "../index.php";
  }
</script>

That’s all I need to do, if profile gets empty, then go to the index, only it’s not working that way there, how can I do?

My html

  • Could post the html?

  • html? html is just a p tag with id profile. I don’t really see the need to post. but it’s like this. <p id="profile"></p>

1 answer

0


var perfil = document.querySelector('#perfil').textContent;
   if (perfil == '') { //seu erro está aqui vc está usando atribuição e não comparação
   window.location.assign("../index.php");
}
  • Not true is not only that, I have tried comparing also, with ==, but also does not work

  • I edited the answer. Try now.

  • I put the assign, even though it doesn’t work, like, when I force the input by the url and there is no logged in user, nothing happens, it is directed to the index

  • So I had to see the html as it is.

  • The ideal is to debug your application in the browser and see how the profile variable is coming and just so do a treatment on it. To further clarify your doubts: https://stackoverflow.com/a/5515349/4312593

  • But I already did, I have to see here even without using the log, the problem is not this, just does not redirect even, I do not know why.

  • I put the html there #Leandro

  • @Francisvagnerdaluz enter then: window.location.href = 'sua_url.php'

  • Worked out then man?

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.