外部弹出onclick在每个会话中仅打开一次 [英] External popup onclick to open only once per session
问题描述
我能够复制功能弹出窗口(编码对我来说是地狱).问题是每次您单击页面时.真烦人作为初学者,我是否有可能,所以我只能为该站点打开一次窗口?这是一个WordPress页面.我插入到正文中的代码. 好,谢谢 这是我写的代码
I was able to duplicate the functional popup (coding is hell for me). The problem is that every time you click on the page. What's annoying. Is there a possibility for me as a beginner, so that I can only open the window once for the site? It's for a wordpress page. The code I inserted into the body. Well thank you Here is the code I wrote
<javascript:void(0);" onClick="window.open('<?php echo "https://prehrajto.cz/hledej/" . $post->post_title ."?cc=uga3bwln" ?>','prehrajto','resizable=yes,scrollbars=yes,');">
我尝试使用此代码,每个会话打开一次,但浏览器被阻止.没关系,它不是onclick函数.
I try this code , its open once per session , but its blocked browser . It would not mind, it's not the onclick function.
<script type="text/javascript">
onClick=window.open('<?php echo "https://prehrajto.cz/hledej/".get_the_title()."?cc=uga3bwln" ?>','prehrajto','resizable=yes,scrollbars=yes,');
</script>
我的编程经验为零.我在合并代码和使用cookie时遇到问题.我迷路了.
And my programming experience is zero. I have a problem to combine code and to work with cookies . Im lost .
推荐答案
是的,您可以使用cookie来做到这一点.
yes, you can do that using cookies .
php具有处理cookie的功能,主要是 setcookie()和同伴
php has functions for dealing with cookies , mainly setcookie() and companions
**/ Set a Cookie /*
add_action( 'init', 'set_mycookie' );
function set_mycookie() {
setcookie( 'cookiename', 'cookievalue', time() + 3600, COOKIEPATH, COOKIE_DOMAIN );
}
**/ Get a Cookie /*
add_action( 'wp_head', 'get_mycookie' );
function get_mycookie() {
$myvar= isset( $_COOKIE['cookiename'] ) ? $_COOKIE['cookiename'] : 'cookie not set';
}
**/ Delete or Unset /*
add_action( 'init', 'unset_mycookie' );
function unset_mycookie() {
setcookie( 'cookiename', '', time() - 3600, COOKIEPATH, COOKIE_DOMAIN );
}
现在,这些当然是最基本的常规示例,但是您可以将其用于任何条件集(例如@Bibberty comment/question),例如按会话,按用户,按天,按页等.任何你想要的.
now, of course these are the most basic general examples, but you could use it with any set of conditions, ( like @Bibberty comment/question ) for example by session, by user, by day, by page, etc . whatever you want .
边注-wp具有使用cookie的专用功能,主要用于身份验证和会话管理(wp默认情况下不启用).请参阅 wp_set_auth_cookie()了解更多信息
Sidenote - wp has dedicated functions for using cookies, mainly for auth and session management ( which wp does not do by default ). see wp_set_auth_cookie() to learn more
侧注2 另外,关于您的代码... 将php嵌入JS(或反之亦然...)是一种不好的做法. wp实际上有一个非常很酷又优雅的功能来处理,如果您真的想学习php/wp-您最好立即开始使用它
sidenote 2 Also, regarding your code ... embading php inside JS ( or viceversa...) is a bad practice. wp has actually a very cool and elegant function to deal with that, and if you really want to learn php/wp - you better start using it now
这篇关于外部弹出onclick在每个会话中仅打开一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!