Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Have a dialog show up only once per user session
Hi and Happy New Year!
On my TXP website I am using a script to show a dialog when the page loads. The script is as follows:
<script>
$(document).ready(function() {
new $.Zebra_Dialog('text...',{
type: "information",
custom_class: "myclass",
title: "title",
width: 600,
animation_speed_show: 1000
});
});
</script>
Trouble is, when the visitor navigates the website and returns to the page, the dialog shows up again. I would like it to show up just once per user session, possibly using sessionStorage. Will someone please help me tweak the above code to get such a result? Thanks very much.
Last edited by gilibaus (2021-01-02 15:23:10)
Offline
Re: Have a dialog show up only once per user session
Would oui_cookie be of help? I do not think that it will recognise sessions, but you can set its expiring time.
<txp:oui_cookie name="hide_dialogue" duration="+1 day" values="yes" />
<txp:if_oui_cookie name="hide_dialogue" not>
<script>
$(document).ready(function() {
new $.Zebra_Dialog('text...',{
type: "information",
custom_class: "myclass",
title: "title",
width: 600,
animation_speed_show: 1000
});
});
</script>
</txp:oui_cookie>
The OK
button should link to href="?hide_dialogue=yes
.
Edited to add that the url resulting after the cookie, is listed by search engines. In this case it will be something like @<txp:site_url /><txp:page_url />?hide_dialogue. Here is a way to prevent that from happening and this is how I implemented it.
Last edited by colak (2021-01-02 14:10:33)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: Have a dialog show up only once per user session
Another idea would be to create your own html based dialogue box and do away with the js.
<txp:oui_cookie name="hide_dialogue" duration="+1 day" values="yes" />
<txp:if_oui_cookie name="hide_dialogue" not>
<div id="my_dialogue"><p>My text</p>
<p><a rel="nofollow noindex noodp noydir nofollow" href="?hide_dialogue=yes">OK</a></p>
</div>
</txp:oui_cookie>
and the untested css
#my_dialogue{
position: absolute;
top: 50%;
left: 50%;
margin-top: -200px;
margin-left: -300px;
width: 600px;
height: 400px;
z-index: 100;
}
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: Have a dialog show up only once per user session
Thank you Colak. The dialog box is already in place and works fine. I will keep your first suggestion as a B plan as I would prefer to use sessionStorage in the script I already have. It’s a simpler solution, no plugins involved and works at a session level. Unfortunately it requires 1-2 more lines of code, and I am not javascript guru at all. Thanks for now.
Offline
Re: Have a dialog show up only once per user session
Indeed, but the balance can be shifted if you do not use jquery anywhere else in your site as its transfer will be heavier for the receiving computers, than just a small plugin on your server.
> Edited to add that this jquery script (note that it is not working on jsfiddle) using the jquery cookie plugin might be of help.
Last edited by colak (2021-01-02 16:53:50)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline