Forum Moderators: open

Message Too Old, No Replies

Javascript If/Then.

based on URL

         

mcjohnson

8:52 pm on Feb 15, 2010 (gmt 0)

10+ Year Member



i have a simple HTML site that I am trying to hide an element (an H1) tag for a specific page. It's a templated system so the pages are created on the fly but output as HTML.

What I want is to hide the H1 element if the particular page is "Stormwater-District.html".

Possible?

birdbrain

9:14 pm on Feb 15, 2010 (gmt 0)



Hi there mcjohnson,

here is a possible solution...


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">

<title></title>

<script type="text/javascript">

function removeHeader(){

n=location.href.split('/');

if(n[n.length-1]=='Stormwater-District.html'){
document.getElementsByTagName('h1')[0].style.display='none';
}
}

if(window.addEventListener){
window.addEventListener('load',removeHeader,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',removeHeader);
}
}
</script>

</head>
<body>

<h1>this is h1 </h1>

</body>
</html>

birdbrain

mcjohnson

12:18 am on Feb 16, 2010 (gmt 0)

10+ Year Member



AWESOME! That worked!

Thank you birdbrain!

birdbrain

7:28 am on Feb 16, 2010 (gmt 0)



No problem, you're very welcome. ;)