简体   繁体   中英

Javascript button not working in IE; working in other browsers

Having problems getting a javascript button to work in IE. I used javascript to create a button that refreshes my page with randomly selected text from a pre-determined array. It works perfectly in Firefox, Chrome, and Safari, but not in IE. In IE, nothing refreshes.

Can anyone help me with a fix so that this Javascript works in IE?

<html>

<head>
    <title>WTF </title>         
</head>

<style type="text/css">

#reason {font-family: "Helvetica", serif; color: white; }

button{
color:#08233e;
font:2.4em Futura, ‘Century Gothic’, AppleGothic, sans-serif;
font-size:70%;
padding:14px;
background:url(overlay.png) repeat-x center #ffcc00;
background-color:rgba(255,204,0,1);
border:1px solid #ffcc00;
-moz-border-radius:10px;
-webkit-border-radius:10px;
border-radius:10px;
border-bottom:1px solid #9f9f9f;
-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);
-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);
box-shadow:inset 0 1px 0 rgba(255,255,255,0.5);
cursor:pointer;
}

button:hover{background-color:rgba(255,204,0,0.8);}

</style>

<body>

    <div class="con">
        <p id="reason" >
    <center><script language="JavaScript">
    var r_text = new Array ();
r_text[0] = "Sample 1";
r_text[1] = "Sample 2";
r_text[2] = "Sample 3";
var i = Math.floor(3*Math.random())
document.write(r_text[i]);
</script>
</p>
<br>   
<a href="" class="button1"><button>TELL ME MORE</button></a><br>
</div> 

</body>

</html>

That is the wrong way to go about refreshing a page. Look at this question . Try changing that and seeing if it works better. Also, the "center" tag is deprecated , so it's best to not use that. And it would be easier to just declare the array like this:

r_text = ['Sample 1', 'Sample 2', 'Sample 3'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM