0

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>
Varun Shetty
  • 409
  • 1
  • 6
  • 13
  • Do you seen any errors in the javascript console? – jrummell Jun 15 '12 at 14:37
  • @jrummell - I dont think its a javascript error, as it works in all the other browsers. this is literally the last thing i need to get working before i can put my site up and its driving me insane. – Varun Shetty Jun 15 '12 at 14:43
  • Each browser has its own javascript engine, and therefore can (and will) parse, execute, and handle errors differently. If you care about your site, check for javascript errors in all browsers. – jrummell Jun 15 '12 at 14:53

1 Answers1

1

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'];
Community
  • 1
  • 1
phenomnomnominal
  • 5,427
  • 1
  • 30
  • 48
  • 1
    Additionally you shouldn't place a button inside an anchor tag. – acme Jun 15 '12 at 14:37
  • I don't think the OP actually wants to refresh the page. I think he/she wants to display a random message. – jrummell Jun 15 '12 at 14:55
  • i took a look at the refresh page question and am going to use this: Will that work in IE? Also, I lost the styling from my original button, what would I need to do to have it styled as my previous, non-working button? – Varun Shetty Jun 15 '12 at 14:57