-2

我写了以下代码:

<script type='text/javascript'>
    var imageID = 0;
    function changeimage(every_seconds) {

        //Change the image
        if (!imageID) {
            document.getElementById("myimage").src = "jesus.jpg";
            imageID++;
        } else { if(imageID==1) {
            document.getElementById("myimage").src="crucifixion.jpg";
            imageID++;
        } else { if(imageID==2) {
            document.getElementById("myimage").src="resurrection.jpg";
            imageID++;
        } else { if(imageID==3) {
            document.getElementById("myimage").src="trinity.jpg";
            imageID=0;
        }}}}

        //Call the same function again for x number of seconds
        setTimeout("changeimage("+every_seconds+")",((every_seconds)*1000));
    }

    var k=0;

    <!--[if gte IE, FF]><!-->

    var k=1;

    <!--><![endif]-->

    function mytext1() {
        if (k==1) {
            document.getElementById("mylink").href="king.html";
            document.getElementById("mytext").innerHTML="THE KING OF KINGS";
        } else { if(k==2) {
            document.getElementById("mylink").href="crucifixion.html";
            document.getElementById("mytext").innerHTML="HE WAS PUNISHED FOR OUR SINS";
        } else{ if(k==3) {
            document.getElementById("mylink").href="resurrection.html";
            document.getElementById("mytext").innerHTML="HE WON DEATH";
        } else { if(k==4) {
            document.getElementById("mylink").href="trinity.html";
            document.getElementById("mytext").innerHTML="THE HOLY TRINITY";
            k=0;
        }}}}
        k++;
    }
</script>

要使程序在所有浏览器中运行,k 在 Chrome 中必须等于 1,在 Internet Explorer 和 Firefox 中必须等于 0。

如何隐藏K=1;Internet Explorer 和 Firefox?

4

1 回答 1

0

要检测 Internet Explorer,您可以使用navigator.appName属性:

if (navigator.appName == 'Microsoft Internet Explorer') k = 1;

要检测 Chrome,您可以使用

if (window.chrome) k = 0;

要检测 Firefox,我建议使用navigator.userAgent属性

if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) k = 1;

另请参阅此问题

于 2013-04-14T09:46:19.907 回答