In my code I am detecting the browser used by user and trying to display different content depending on the browser they use.
but java script code is not properly working. My web application is built on asp.net and vb.net.
here is my code
<asp:Content ID="Content2" ContentPlaceHolderID="mainContent" runat="Server">
<div class="btn-wrapper" id="regular-content">
<asp:Button runat="server" ID="uxLoginButton" Text="Login" />
<asp:Button runat="server" ID="uxRegister" Text="Register" />
</div>
<div id="safari-content">
<p>Use another Browser </p>
</div>
</asp:Content>
So if the user is using any browser other than safari then i want to display the content where div id = "regular-content" . and if the user is using safari then i want to display the content where div id = "safari-browser"
in my javascript code i have detected if the user is using safari .
<asp:Content ID="Content3" runat="server" ContentPlaceHolderID="ScriptContent">
<script type="text/javascript">
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
//document.body.innerHTML = isSafari;
this detects browser properly. if the browser is safari the then the value of isSafari is true and if not the value is false.
if (isSafari == "true") {
document.getElementById("safari-content").style.display = 'block';
document.getElementById("regular-content").style.display = 'none';
}
else{
document.getElementById("safari-content").style.display = 'none';
document.getElementById("regular-content").style.display = 'block';
}
But this does not work properly. In all cases it shows the regular browser content. i.e if the user is using safari he should not see the regular browser content. but he sees the regular browser content. not the safari content
How can i fix this?
Aucun commentaire:
Enregistrer un commentaire