小编DaK*_*der的帖子

如何只显示第一次访客特定的工具提示?

我想只给第一次用户一个"浏览"我的网站.我想用JavaScript做.我的意思是,如果用户从未见过我的网站并且这是他/她的第一次访问,他们将获得有关如何使用该网站的教程.如果他们再次访问或重新加载页面,他们不应该看到工具提示.这可以用JavaScript Cookies完成吗?我发现了一个PHP代码,但我现在想要避免使用PHP.

<?php
// Top of the page, before sending out ANY output to the page.
    $user_is_first_timer = !isset( $_COOKIE["FirstTimer"] );

// Set the cookie so that the message doesn't show again
    setcookie( "FirstTimer", 1, strtotime( '+1 year' ) );
?>




<H1>hi!</h1><br>


<!-- Put this anywhere on your page. -->
<?php if( $user_is_first_timer ): ?>
    Hello there! you're a first time user!.
<?php endif; ?>
Run Code Online (Sandbox Code Playgroud)

如果不能用JS完成,可以用.htaccess完成吗?我也发现了这个:

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^(www\.)?(https?://)?(?!example\.com) [NC]
Rewriterule ^(.*)$ http://example.com/welcome.html [r=307,NC]
Run Code Online (Sandbox Code Playgroud)

html javascript cookies .htaccess

1
推荐指数
1
解决办法
1681
查看次数

如何使用JavaScript切换元素的边距?

我试图通过改变边距将一个div移到一边,然后返回一个转换.我有一个按钮,我想切换它的边距.div向右移动,但是当我再次单击时,它不会移回到它的原始位置.这就是我所拥有的:

HTML

<div id="movingdiv">
<a href="#" onclick="toggle()">Click Me!</a>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS

#movingdiv {
overflow: hidden;
left: 0;
top: 0;
right: 0;
bottom: 0;
background-color: gray;
-webkit-transition-duration: 0.3s;
-moz-transition-duration: 0.3s;
-o-transition-duration: 0.3s;
transition-duration: 0.3s;
}
Run Code Online (Sandbox Code Playgroud)

JavaScript的

function toggle () {

var el = document.getElementById("movingdiv");
if ( el.style.marginLeft="250px" ) {

    el.style.marginLeft="250px";

}

else {

    el.style.marginLeft="0px";

}

}
Run Code Online (Sandbox Code Playgroud)

它在行动:http: //codepen.io/dakoder/pen/nfimJ

html javascript toggle

-3
推荐指数
1
解决办法
1005
查看次数

标签 统计

html ×2

javascript ×2

.htaccess ×1

cookies ×1

toggle ×1