/    Sign up×
Community /Pin to ProfileBookmark

show div onLoad by host location

Hi All,

I can’t seem to figure this out, what im trying to do below is to show a div layer by host location, but doesnt work. any ideas?

[code=html]
<script type=”text/javascript” language=”JavaScript”>

var b = “www.yahoo.com”;
var p = “www.msn.com”;

if (location.host = b)

{
document.getElementById(x).style.display = “block”;
}

else if (location.host == p)
{
document.getElementById(a).style.display = “block”;
}

</script>

<style type=”text/css”>
#x {

z-index:1;
display: none;
}
#a {

z-index:2;
display: none;
}

</style>
</head>

<body>
<div id=”x”>
<p>Content X</p>
<p>Content X</p>
<p>Content X</p>
</div>
<div id=”a”>
<p>Content A</p>
<p>Content A</p>
<p>Content A</p>
</div>
</body>
</html>
[/code]

thank you

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@ilawtonAug 11.2009 — Firstly, you need to put quotes around "a" and "x". Secondly there needs to be 2 equals signs in the if statement (you only had one). And lastly, and most importantly, you needed to have the Javascript after the html elements to which they are trying to manipulate.

Code below should work (assuming you're not using msn and yahoo).


[CODE]



<style type="text/css">
#x {

z-index:1;
display: none;
}
#a {

z-index:2;
display: none;
}

</style>
</head>

<body>
<div id="x">
<p>Content X</p>
<p>Content X</p>
<p>Content X</p>
</div>
<div id="a">
<p>Content A</p>
<p>Content A</p>
<p>Content A</p>
</div>


<script type="text/javascript" language="JavaScript">

var b = "www.yahoo.com";
var p = "www.msn.com";

if (location.host == b)

{
document.getElementById("x").style.display = "block";
}

else if (location.host == p)
{
alert(document.getElementById("a"));
document.getElementById("a").style.display = "block";
}

</script>

</body>
</html>


[/CODE]


Does that help?
Copy linkTweet thisAlerts:
@drodaxauthorAug 11.2009 — Excellent! works like a charm. Thanks ilawton!
×

Success!

Help @drodax spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...