0

First of all a little background so that you guys don´t respond so harshly, I´ve been learning code for the past month and a half. I´ve been having trouble hiding a window that shows up if your browser language is not in English. I know there are other ways to go around it but I would like to know why it isn´t working, I just don´t want to give up on it and try to understand it. I want the window to disappear when I press the no button. HERE IS AN IMAGE OF THE WINDOW https://imgur.com/gallery/iTEX0I0 Here is the code:

var lang = navigator.language;
if ("" + lang == "es-US") {
  var div = document.getElementById("win");
}
var button = document.getElementById("buttonn")
buttonn.onclick = function() {
  var div = document.getElementById("win");
  if (div.style.display !== "none") {
    div.style.display = "none";
  }
}
<body>
  <div class="container">
    <div class="window" id="win">
      <div class="layover">
        <div class="h2">
          <h2>Oops!</h2>
        </div>
        <div class="yesandno">
          <figure class="yes">
            <button onclick="window.location.href= 'espanol.html';">Si</button>
          </figure>
          <figure class="no">
            <button onclick id="buttonn">No</button>
          </figure>
        </div>
        <div class="langmessage">
          Hemos detectado que el idioma de su ordenador se encuentra en español. ¿Le gustaría utilizar la versión en español de nuestro sitio web?
        </div>
      </div>
    </div>
Ankit Sharma
  • 3,923
  • 2
  • 29
  • 49
Roger99
  • 61
  • 1
  • 6
  • 1
    what kinda window shows up can you show us a screenshot? also formatted your code properly –  Mar 29 '20 at 19:35
  • https://imgur.com/gallery/iTEX0I0 here is the window showing up – Roger99 Mar 29 '20 at 19:43
  • is this what you're looking for? https://stackoverflow.com/a/12238414/9201277 –  Mar 29 '20 at 19:47
  • nope, i just want the window to disappear when i press the no button but it doesnt – Roger99 Mar 29 '20 at 19:49
  • so you want the `iframe` to disappear if that's an iframe in the screenshot, I mean the example that I updated works well no? –  Mar 29 '20 at 19:51
  • i dont know what an iframe is, i just want to hide the
    , which is the div that i used in css to create the window, etc
    – Roger99 Mar 29 '20 at 19:54

2 Answers2

1

I don't see anywhere that you are checking if the browser language is in fact in English. The English language code is "en-US". You used "es-US" in an if statement, but that is the language code for Spanish.

PhilCowan
  • 523
  • 5
  • 13
  • yes, sorry i meant that the window shows up when it detects that yourt browser language is in spanish – Roger99 Mar 29 '20 at 19:44
0

I think there's a typo on line 6, change buttonn to button, see if that works.
I have added the snippet that works fine, according to your need.

var button = document.getElementById("buttonn");
buttonn.onclick = function() {
 var div = document.getElementById("win");
    if (div.style.display !== "none") {
        div.style.display = "none";
    }
}
<!DOCTYPE html>
<html>
<body>

<button type="button" id="buttonn">No</button>
<div id='win' style="height: 200px; width: 200px; border: 1px solid black"></div>



</body>
</html> 
sauhardnc
  • 1,961
  • 2
  • 6
  • 16
  • oh yeah, i changed it but still doesn´t hide the
    – Roger99 Mar 29 '20 at 19:56
  • 1
    I tried this code and it works perfectly-- `

    My First JavaScript

    ` Also your code snippet works just fine.
    – sauhardnc Mar 29 '20 at 20:10
  • Dude, thank you so much, i figured thanks to your code that i forgot to add `var div= DOCUMENT.getElementById("win")` on my code – Roger99 Mar 29 '20 at 20:14
  • 1
    Happy to help. :) Mark the answer as accepted if that helped you. :) – sauhardnc Mar 29 '20 at 20:17