如何在没有javascript的情况下检测浏览器和显示消息?

时间:2015-10-10 20:04:17

标签: javascript jquery internet-explorer

好的,所以我的网站在Internet Explorer中无法正常工作,除非用户在首次访问时点击“允许阻止的内容”。现在我想出了一些javascript来检测打开网页的浏览器,并弹出一个显示为:'你在Internet Explorer中。请在重新加载时单击页面底部的“允许阻止的内容”,以允许运行脚本和ActiveX控件。否则该网站可能无法正常运行。但它本身就是一个脚本,因此用户只有在推送它时才能看到它。现在它没用了,因为它告诉用户只有在他们允许之后才点击按钮。 我的JS是:

/*
 * To change this license header, choose License Headers in Project     Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package minimumcoinsproject;
import java.util.Scanner;
 /**
 *
  * @author user
  */
 public class MinimumCoinsProject {

/**
 *
 * @author 
 */
static public class MinumimCoinsProject//a class is not an object, but a     blueprint for an object. It is the building blocks.
{

}
public static void main(String[] args) {
    // TODO code application logic here
    { //initialization

        int change = 0;
        int quarters = 0;
        int dimes = 0;
        int nickels = 0;

    Scanner in;
    in = new Scanner(System.in);
    System.out.println("Lets calclulate the minimum coins.\n");
    System.out.println("PLease enter amount of change.(1-99)\n");
    change=in.nextInt(); //asks for the amount of change to calculate


    //start of while loop
        while  ( change >= 25)
    {
        quarters = quarters+1;
        change = quarters - 25;
        System.out.printf("Quarters:\n", quarters);
    } 
        if (10 >= change)
    {

        dimes = dimes + 1;
        change = change - 10;
        System.out.printf("Dimes: \n", dimes);

    }
        if  (change >=5) 
    {

        nickels = nickels + 1;            
        change = change - 5;
        System.out.printf("Nickles: \n",nickels);

    }
        if ( change == 0)
        System.out.printf("Pennies: \n", change);
    }
}

我需要一种方法来检测浏览器并显示没有任何JS或JQuery的消息。有人有想法吗?

2 个答案:

答案 0 :(得分:3)

在网站上为每个用户显示一个文本,并使用JavaScript隐藏它,因此只有未启用JavaScript的用户才能看到它。使用这种方法,每个用户(也在IE之外的其他浏览器中)都可以看到它,因此它应该更加通用。

HTML:

<div id="js-message">You don't have JavaScript enabled, please enable it.</div>

JavaScript(在页面加载时):

$(function() {
     $('#js-message').remove();
});

答案 1 :(得分:0)

将javascript移动到上面加载ActiveX控件的head标签中,并在那里调用alert函数:

if (window.navigator.userAgent.indexOf("MSIE ") > -1) {
    alert('You are in Internet Explorer...');
}

如果这不起作用,请将邮件放在页面顶部的div中以粗体显示并隐藏它:

<div id="ienotice">You are in Internet Explorer...</div>

setTimeout(function() {
    document.getElementById('ienotice').style.display = 'none';
}, (window.navigator.userAgent.indexOf("MSIE ") > -1) ? 5000 : 0);