PDA

View Full Version : Why Won't This Appear?



Clayf700
09-01-2010, 12:13 AM
Okay! so what i'm trying to do is make this table appear only in firefox here's my code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Appear In Firefox</title>
<script type="text/javascript">
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
{
document.getElementById('Table').style.display='block';
}
</script>
</head>
<body>
<table width="200" border="1" id="Table" style="display:none;">
<tr>
<td>&nbsp;</td>
</tr>
</table>
</body>
</html>

Why isn't it working?
Any Help is appreciated

azoomer
09-01-2010, 12:30 AM
you could try something like this instead

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Appear In Firefox</title>
<style type="text/css">
#Table { display:none;}
</style>
</head>
<body>
<table width="200" border="1" id="Table">
<tr>
<td>&nbsp;</td>
</tr>
</table>
<script type="text/javascript">
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
{
document.getElementById('Table').style.display='block';
}
</script>
</body>
</html>

jscheuer1
09-01-2010, 06:40 PM
That will 'work', but get you a messed up table because the native display of a table in Firefox is not 'block'. I think it's 'table', but that could change. This is relatively foolproof:


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Appear In Firefox</title>
<style type="text/css">
#Table {
width: 200px;
border: 1px outset #000;
}
#Table td {
padding: 1px;
margin: 1px;
border: 1px inset #000;
}
</style>
</head>
<body>
<table id="Table" style="display: none;">
<tr>
<td>&nbsp;</td>
</tr>
</table>
<script type="text/javascript">
if(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
document.getElementById('Table').style.display = '';
}
</script>
</body>
</html>

Notes: Attributes of the table moved to style as per HTML 5 standards. A browser 'spoofing' itself to be Firefox will see the table. With no javascript, no one will see the table. Except that with all css disabled, anyone can see it.