0

I have created a SharePoint 2013 page with HTML Iframe. As Iframe is not working with certain browsers, for example, Chrome. I need to alert or show a message when the page is not opened with IE. Can you please let me know how to achieve this?

2 Answers 2

1

Note that detecting browsers is not reliable, but you can try this:

var isIE = /*@cc_on!@*/false || !!document.documentMode; 
if (!isIE) {
    alert("This is not IE");
}

This is not my work, I got it from How to detect Safari, Chrome, IE, Firefox and Opera browser?

This trick uses duck-typing. Please go to this page and read the pros and cons before using it in production.

EDIT: I believe my first answer met your question, but since you elaborated further in your comment, I have another code snippet for you.

As previously stated: browser detection is not reliable but since you want to try it, here's a suggestion. This combines the duck-typing example with checking the user agent:

if ((window.navigator.userAgent.indexOf('Edge') == -1) && !(/*@cc_on!@*/false || !!document.documentMode)) {
    alert('This is not IE or Edge');
} 
else {
    alert('This is IE or Edge');
}

I have tested this in IE11, Edge, Chrome and Firefox Dev ed. You can try window.navigator.userAgent in any browser to see the difference.

Also, check this post.

2
  • Hi Papageno, can you please advise how to detect if the browser is not IE OR Edge, then send the alert? Is it possible to detect two browsers? thanks,
    – T Zhang
    Feb 1, 2018 at 13:17
  • Please find my advise in my updated answer,
    – Papageno
    Feb 1, 2018 at 21:38
0

You can check if current browser is Chrome and alert a warning message like below:

<script type="text/javascript">
   IEBrowserDetection();

 function IEBrowserDetection() {
   if (navigator.userAgent.search("Chrome")>= 0) {
        // insert conditional Chrome code here
        alert("Current browser is Chrome, this page needs to be accessed by IE, please use IE instead");
        return false;
    }
}
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.