[英]Change image from meta title with Javascript?
I have an image for logging in set with css, and want to change this to a logged out image when users are logged in. There is no variables to use, except a small change in the sites meta title. 我有一个用于css的登录图像,并且想要在用户登录时将其更改为已注销的图像。没有可用的变量,除了站点meta标题有很小的变化。 Would this be possible with vanilla Javascript?
使用香草Javascript可以实现吗?
the title: 标题:
<title>Text</title>
When logged in it adds, amongst the username a line 登录后,在用户名中添加一行
<title>Text - </title>
css: CSS:
.navLogin {
display: block;
position: absolute;
background-image: url('/img/account.png');
background-position: center;
background-repeat: no-repeat;
}
Try using this: 尝试使用此:
$("meta[property='yourProperty']").attr("content", newTitle);
EDIT 编辑
if(checkSomething()){
var oldTitle = document.title;
var newTitle = "NEW";
document.title = oldTitle + newTitle;
var link = document.createElement('link');
link.rel = 'shortcut icon';
link.href = "example.jpg";
document.getElementsByTagName('head')[0].appendChild(link);
}
If I understand correctly you want to check if user is logged in based on tittle? 如果我理解正确,您是否要根据标题检查用户是否登录? Then:
然后:
if($('tittle').text() == loggedInTittle)
{
//user is logged in so change image e.g
$('.navLoggedOut').removeClass('.navLoggedOut').addClass('.navLogin');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.