Reputation:
I'm trying to show notification to the users if the browser is not Chrome.
What I did till now is
the div to show when if browser is other than chrome:
<div id="notify"> Please use chrome browser </div>
the CSS:
#notify{
display:none;
}
and the Javascript as found here:
<script>
var isChrome = !!window.chrome && !isOpera;
if(isChrome==false) //if the browser is not chrome
{
alert("Please Use chrome browser"); // this works
document.getElementById('notify').show(); //this doesn't work
}
</script>
the script is place above the div tag.
What is wrong with the second statment?
Upvotes: 2
Views: 745
Reputation: 201568
If you really must do such a thing, change the content of the document instead of just styling (which will be ignored in some situations). And manipulating an element, is possible only after the element has been parsed. Example:
<div id="notify"></div>
<script>
if(!window.chrome || isOpera) {
document.getElementById('notify').innerHTML =
'Please use the Chrome browser.';
}
</script>
Upvotes: 0
Reputation: 36511
show
is not a native method of Javascript. If you are using jQuery, the correct syntax would be
$('#notify').show()
if you are using vanilla javascript you should use:
document.getElementById('notify').style.display = 'block';
Also put the script
below the div
tag.
Upvotes: 4
Reputation: 7332
$("#notify").show()
instead of
document.getElementById('notify').show();
Upvotes: 1
Reputation: 22711
Try using,
document.getElementById('notify').style.display='block';
instead of ,
document.getElementById('notify').show();
Upvotes: 1
Reputation: 67207
Please don't mix up Jquery's .show() function with JavaScript's selector. Please read this for full reference, Jquery ID selectors
Instead of this,
document.getElementById('notify').show();
Use this,
$('#notify').show();
Upvotes: 1