admin管理员组文章数量:1353453
I do not know why but I have problems with this code. The banner is displayed on every page although it has specified the attribute $(location).attr('href') you can help me?:
<div id="bottombar">
<div class="bottom-content">
<a href="/" target="_blank"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/banner/bottom-logo.png" alt="player-logo" /></a>
<a href="/" target="_blank"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/banner/bottom-txt.png" alt="player-slogan" /></a>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/banner/bottom-download.png" alt="player-download" />
</div>
<div id="bottombarClose"><p>Chiudi</p></div>
<script type="text/javascript"">
$(document).ready(function() {
var currentUrl = $(location).attr('href');
if(currentUrl == '/')
$('#bottombar').show();
$("#bottombarClose").click(function() {
$('#bottombar').hide();
});
});
</script>
</div>
CSS Code:
div#bottombar {
background-image: url(images/banner/player-bg3.png);
background-repeat: repeat-x;
bottom: 0;
color: #FFFFFF;
font-family: Arial,Helvetica,sans-serif;
height: 100px;
left: 0;
margin: 0;
position: fixed !important;
width: 100%;
z-index: 99999;
display:none;
}
.bottom-content {
bottom: 0;
height: 97px;
left: 50%;
margin-left: -495px;
position: absolute;
width: 960px;
z-index: 10;
}
#bottombarClose {
cursor: pointer;
float: right;
padding: 55px 10px 0 0;
}
I do not know why but I have problems with this code. The banner is displayed on every page although it has specified the attribute $(location).attr('href') you can help me?:
<div id="bottombar">
<div class="bottom-content">
<a href="http://www.cliente/" target="_blank"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/banner/bottom-logo.png" alt="player-logo" /></a>
<a href="http://www.cliente/" target="_blank"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/banner/bottom-txt.png" alt="player-slogan" /></a>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/banner/bottom-download.png" alt="player-download" />
</div>
<div id="bottombarClose"><p>Chiudi</p></div>
<script type="text/javascript"">
$(document).ready(function() {
var currentUrl = $(location).attr('href');
if(currentUrl == 'http://www.esempio/')
$('#bottombar').show();
$("#bottombarClose").click(function() {
$('#bottombar').hide();
});
});
</script>
</div>
CSS Code:
div#bottombar {
background-image: url(images/banner/player-bg3.png);
background-repeat: repeat-x;
bottom: 0;
color: #FFFFFF;
font-family: Arial,Helvetica,sans-serif;
height: 100px;
left: 0;
margin: 0;
position: fixed !important;
width: 100%;
z-index: 99999;
display:none;
}
.bottom-content {
bottom: 0;
height: 97px;
left: 50%;
margin-left: -495px;
position: absolute;
width: 960px;
z-index: 10;
}
#bottombarClose {
cursor: pointer;
float: right;
padding: 55px 10px 0 0;
}
Share
Improve this question
edited Jun 13, 2011 at 12:12
Branko
asked Mar 29, 2011 at 14:26
BrankoBranko
1752 gold badges3 silver badges14 bronze badges
2
- what is 'location' in your code? – Rob Levine Commented Mar 29, 2011 at 14:29
-
1
Why do you think
$(location).attr()
should work at all? – Felix Kling Commented Mar 29, 2011 at 14:32
6 Answers
Reset to default 6Don't you mean just location.href
?
This is assuming you are talking about window.location
and not something else.
Returns a Location object, which contains information about the URL of the document and provides methods for changing that URL. You can also assign to this property to load another URL.
Location is not an element in the dom thus jQuery can not select it.
So your code would be like so:
var currentUrl = window.location.href;
location
is not a DOM Element, it is a Location object.
You are trying to create a jQuery object from it, but it does not make sense.
Use this instead:
var currentUrl = window.location.href;
Try this
var currentUrl = window.location.href;
Try using var currentUrl = window.location.href
instead. This will return the location of the current page.
ok, I made the change in this way, but did not seem to work:
$(document).ready(function() {
var currentUrl = window.location.href;
if(currentUrl == 'http://streamingdb/')
$('#bottombar').show();
$("#bottombarClose").click(function() {
$('#bottombar').hide();
});
});
then I added a "display:none" to div#Bottombar and everything works. Thanks to all of your time.
Instead of
$(location).attr('href');
use
currentUrl = location;
本文标签: javascript(location)attr(39href39) not workingStack Overflow
版权声明:本文标题:javascript - $(location).attr('href'); not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743857430a2551110.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论