3

I have seen this link.

Browser detection in JavaScript?

My problem is slightly different .This link is for normal web pages. I want to detect browser from an iframe and want to display different content on the basis of browser.

let me explain in detail

We have built an application with asp.net and vb.net. Our client can integrate this application into their website as an iframe.

There are 10-12 pages in this iframe. code for one of the iframe page is like

<%@ Page Title="" Language="VB" MasterPageFile="~/cn/MasterPage.master" AutoEventWireup="false" CodeFile="login.aspx.vb" Inherits="pn_login" %>

<asp:Content ID="Content2" ContentPlaceHolderID="mainContent" runat="Server">
<h2>Register or log in to apply</h2>
    <div class="login-wrapper" id="safari">
         XXXXXXXXXXX
    </div>
    <div class="login-wrapper" id="other">
         YYYYYYYY
     </div>

<asp:Content ID="Content3" runat="server" ContentPlaceHolderID="ScriptContent">

<script type="text/javascript">

 var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;

</script>

The iframe and its pages works fine with all browser except from safari.So I only needed to detect if the browser is safari. The script code determines if the browser is safari. If the value of variable isSafari is true then the user uses safari otherwise the value is false.

So far so good. now we want to display different content depending on the variable. i.e.

if isSafari==True then 
     <div class="login-wrapper" id="safari"> xxxxx </div>
else
     <div class="login-wrapper" id="other"> yyyy </div>

How can i do that?

For more information

Our web application is using master page and also database dependent. In master page we are already using a javascript function under body onload.

The code for iframes master page is .

<body onload="iframeResizePipe()">
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />

    <div class="careers  b-<%: CInt(Request("b"))%>">
        <asp:ContentPlaceHolder ID="mainContent" runat="server" />

    </div>
</form><br />

</body>

Please note

i dont want to just check the browser and tell user which browser they are are using. users know which browser they are using. i want to to detect the browser in the back end . if the user is using safari then i want to show him a different content. and if they are not using safari the content will be different

and i have also seen this link https://www.whatismybrowser.com/developers/tools/iframe. its not what i want

appreciate your suggestion.

Thanks

Community
  • 1
  • 1
Bashabi
  • 696
  • 1
  • 12
  • 40

2 Answers2

1
if (isSafari) {
document.getElementById("safari").style.display = 'block';
document.getElementById("other").style.display = 'none';
} 
else {
document.getElementById("safari").style.display = 'none';
document.getElementById("other").style.display = 'block';
}
Bashabi
  • 696
  • 1
  • 12
  • 40
0

the simplest way to check the browser is features tag. the sample code from another web is as. <iframe src="https://www.whatismybrowser.com/feature/iframe?capabilities=true" width="600" height="270" style="border: none;"></iframe>

Zeshan Khan
  • 294
  • 2
  • 15
  • you did not get my question properly. i dont want to just check the browser and tell user which browser they are are using. users know which browser they are using. i want to to detect the browser in the back end . if the user is using safari then i want to show him a different content. and if they are not using safari the content will be different. – Bashabi Dec 03 '15 at 13:26
  • Microsoft provided a vb code to check the browser its at https://msdn.microsoft.com/en-us/library/3yekbd5b.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1 – Zeshan Khan Dec 03 '15 at 13:29
  • is this the question that you are asking or describe a bit more please. – Zeshan Khan Dec 03 '15 at 13:30
  • the latest link detects browser and tells when user clicks the button which i dont want. is there anything else where the user have to do nothing just if they are using safari then the html content (not an alert box) in the iframe will tell them to use another browser. – Bashabi Dec 03 '15 at 13:34
  • The code that is provided on button click event could be called at page load. in the page load we may change the content of that page to show at the user side. – Zeshan Khan Dec 03 '15 at 13:36
  • edited my question. please have a look and suggest if you can. thanks – Bashabi Dec 03 '15 at 16:16