Welcome to WebmasterWorld Guest from 54.226.47.198

Forum Moderators: open

Message Too Old, No Replies

Javascript If/Then.

based on URL

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

Junior Member

10+ Year Member

joined:July 8, 2004
posts: 175
votes: 0


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?
9:14 pm on Feb 15, 2010 (gmt 0)

Senior Member from GB 

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 2, 2003
posts: 970
votes: 23


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
12:18 am on Feb 16, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:July 8, 2004
posts:175
votes: 0


AWESOME! That worked!

Thank you birdbrain!
7:28 am on Feb 16, 2010 (gmt 0)

Senior Member from GB 

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 2, 2003
posts: 970
votes: 23


No problem, you're very welcome. ;)