I have a question…
I have a website developed especially for Chrome, and i want to show a notification (for say people use Google Chrome) only to user they’re not using Chrome. I think it should be like this on Javascript:
var isChrome = navigator.userAgent.indexOf("Chrome/") > -1;
if (isChrome) {
document.getElementById('notification').style.display = 'none';
}
but when I did this, I got an error ( in Google Developer Inspector: JS Console) saying this:
Uncaught TypeError: Cannot read property ‘style’ of null
so what am I doing wrong¿?
Thanks in advance.
PD. Sorry for my English, I speak a little of it!
You’re probably trying to run that code before your whole HTML is read into a DOM. Register it as an event handler for the “load” or “ready” events. (The best way to do this depends on whether you’re using a Javascript framework or just pure JS.)