I would like to implement it in a way where when the user has visited my page for the first time.
They will have a pop up appearing like a forum message " Hi , you've just visited our forum "
So when the second time the same user visit , the pop up will disappear .
Here's my code I'm working on :
var beenherecookie = 'FE44been644';
var beenherebegin = document.cookie.indexOf(beenherecookie);
if (beenherebegin > -1){
//Want to implement the code of when user enter first time , "style="display:none;"
else{
function setTimeout("style="display:block;", 60000 * 10); ; //set to 1000 X number of desired delay seconds. So 2 minutes (120 seconds) is 120 X 1000 =
120000
WriteCookie("FE44been644","yes");}
Here's my HTML code for the style::
style="javascript:meh(the function of the style which changes)"
So here's the situation :
When the user visit the website for the first time,
The javascript function meh would be style="display:none"
If the user has entered the website previously
The javascript function meh would be style="display:block"
I need some favors thanks in advance
There are several ways you can implement the scenario..
declare your meh function
var meh = function(){}
if (beenherebegin > -1){
meh = function(){
document.getElementById('popupID').style.display='none';
}
}
else{
meh = function(){
document.getElementById('popupID').style.display='block';
}
}
EDIT
var isFirstTime = false;
var popupHandler = function(firstTime){
if(firstTime){
return "block";
}
else{
return "none";
}
}
if (beenherebegin > -1){
isFirstTime = false;
}
else{
isFirstTime = true;
}
document.getElementById('popupID').style.display= popupHandler(isFirstTime);
Hello,
Once you use the cookie profiling to identify if the user has visited before. You can use document.getElementById.show() and document.getElementById.hide() methods to achieve what you are trying to do. There would be a div element enclosing the popup code, so you can use that. Please tell me if this helps or not. Additionally you can also use jquery methods for show/hide.
Thank You
Related
I take the liberty of posting this topic because I find myself in a situation that I can't explain.
I created a stopwatch that allows to record the time spent when clicking on stop (it also sends the client id, the comment left by the employee, the creation date and the person who did the work).
For security reasons, I blocked the submit button once the user has clicked once. I also offer the possibility to save a task and resume it later. And here, while the html code of the stopwatch is identical, it doesn't work anymore. Indeed, you can click twice before it freezes (and not once as before).
Here is what the button looks like when you click :
Here is the corresponding JavaSript code :
function verifComm(text){
console.log('verifComm');
if(text.value.length < 5){
return false;
}
else {
var n = 1;
btnSend = document.getElementById("envoi");
btnSave = document.getElementById("sauv");
btnSend.addEventListener('click', function desactiverEnvoiBouton(){
document.getElementById('envoi').value='Envoi en cours...';
document.getElementById('envoi').style.opacity = "0.5";
if(n>1){
document.getElementById('envoi').disabled=true;
}
n = n+1;
console.log('Clic sur envoi');
});
btnSave.addEventListener('click', function desactiverSauvegardeBouton(){
document.getElementById('sauv').value='Sauvegarde en cours...';
document.getElementById('sauv').style.opacity = "0.5";
if(n>1){
document.getElementById('sauv').disabled=true;
}
n = n+1;
});
return true;
}
}
// Vérification avant envoi du formulaire
function verifForm(f){
var CommOk = verifComm(f.commentaireEnregistre);
var CommSaveOk = verifComm(f.commentaireSauvegarde);
if( (CommOk) || (CommSaveOk)){
return true;
}
else{
alert("Veuillez commenter la tâche (minimum 5 caractères)");
return false;
}
}
And this is what the code of the page looks like: (I made a screenshot because I can't share my code, he doesn't want to publish the topic otherwise)
If you need more code or explanations, don't hesitate to let me know.
Thank you in advance for your answers.
I look forward to hearing from you,
Damien
Im trying to figure out how to in wordpress display only first two comments and hide rest and add button that reveal all these hidden messages if needed. Pagination give me only two msg per page and thats not im looking for. Can someone give me an idea how I can this achieve or point me to articles about this?
Thanks
here is a plugin that should do the job: https://wordpress.org/plugins/comment-load-more/
It is a bit outdated (3 years ago) so you should check if the code is still valid and compatible.
In " Settings > Comment Load" you should be able to set the number of desired comments to show first.
Indeed, in this guide - http://www.wpbeginner.com/plugins/how-to-easily-lazy-load-comments-in-wordpress/ - you will find how to lazy load all comments. Probably, with some modification, you can adapt it to your need as well.
Cheers!
// This function hide comments if is there more than two and add show more button
function fds_comments () {
var commentWrap = document.getElementById('comment-list');
var commentChilderns = commentWrap.children;
for (var i = 2; i < commentChilderns.length; i++) {
commentChilderns[i].style.display = "none";
}
commentWrap.innerHTML = commentWrap.innerHTML + "<button id='more-comments' onclick='fds_all_comments()'type='button' >Show all comments</button>";
}
//This function reveal all comments (used on SHOW MORE btn)
function fds_all_comments(){
var commentWrap = document.getElementById('comment-list');
var commentChilderns = commentWrap.children;
for (var i = 0; i < commentChilderns.length; i++) {
commentChilderns[i].style.display = "block";
}
}
// problem: comments hidden after submit
// solved: This additional code reveal comments after SUBMIT
window.onload = function() {
var reloading = sessionStorage.getItem("reloading");
if (reloading) {
sessionStorage.removeItem("reloading");
fds_all_comments();
}
}
// function used on SUBMIT button
function fds_all_on_submit(){
sessionStorage.setItem("reloading", "true");
document.location.reload();
}
I have a request that goes beyond my very basic scripting abilities. I have a website with a message that tells users how many days they have left until their password expires:
"John doe's password expires in 91 days"
I'd like to add some script that evaluates this statement, which is contained in a div of class "expiryNotice," extract the number, and basically hide the entire div if greater than 60.
I've written JS/jQuery to do static modifications before, but never anything with any kind of logic, so I am a bit lost with where to begin.
Any help would be much appreciated!
Caveat, there are probably more reasonable ways to go about this than parsing the text in the message div, but this will do it:
$(function(){
var msg = $('#notice').text()
var days = msg.match(/\d+/)[0]
console.log(days)
if(Number(days) > 60) {
$('#notice').hide()
}
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="notice">"John doe's password expires in 91 days"</div>
function CheckExpiryNotice(maxNum) {
var expiryNoticeDiv = $('.expiryNotice');
var expiryNoticeStr = expiryNoticeDiv.text();
$(expiryNoticeStr.split(" ")).each(function(i,e) {
if($.isNumeric(e)) {
if(e > maxNum) {
expiryNoticeDiv.hide();
}
}
});
}
Calling this function should work CheckExpiryNotice(60);
You can do something like this in javascript, if you don't want to use jQuery:
var elem = document.getElementsByClassName('expiryNotice');
var str = elem[0].innerText;
var days = str.match(/\d+/)[0];
if (+days > 60) {
elem[0].hidden = true;
}
I want to display dynamic information (score) in the window tab of a javascript games running in a browser (chrome) : my goal is to run several instances of the game in different tabs, running in parallel, and to be able to see the current scores in the tab titles. I tried :
document.title = score
... but it works only in the selected tab, the other one are not refreshed until selected (although the games are running well in background).
==> is there a way to force the update of the tab titles... even if not selected ?
I found couple of same questions on the http://stackoverflow.com but they did not work for me.
You can find your solution here: http://www.raymondcamden.com/2010/10/19/Using-JavaScript-to-update-the-browser-window-title-when-the-user-is-away
So, basically that kind of code will work:
var focused = true;
var baseTitle = "";
var chatsMissed = 0;
//I'm the fake function that represents some process. We randomly determine if a new chat happened
function fakeStuff() {
if(Math.random() > 0.5) {
if(!focused) {
chatsMissed++;
window.document.title = baseTitle + " ("+chatsMissed+")";
}
}
}
$(document).ready(function() {
//store the base title
baseTitle = window.document.title;
//When the window is focused...
$(window).focus(function() {
focused = true;
// window.document.title = baseTitle;
//chrome bug: http://heyman.info/2010/oct/7/google-chrome-bug-when-setting-document-title/
setTimeout(function() {
document.title = baseTitle;
}, 100);
chatsMissed = 0;
});
//When the window is blurred...
$(window).blur(function() {
focused = false;
});
//setup a process
window.setInterval('fakeStuff()',2000);
})
Unfortunately JSfiddle do not support title changing. But I tested, and it works.
I am trying to get this to work in my iweb page hosted not on MobileMe. With the code below I continue to get the alert box on each refresh of the page instead of once per session. I am a total newbie here so be kind please.
//Alert message once script- By JavaScript Kit
//Credit notice must stay intact for use
//Visit http://javascriptkit.com for this script
//specify message to alert
var answer=confirm("Click OK if you have been cleared Sutter's HR department to start
volunteering.")
if (answer)
alert ("Excellent!! Please select your dates directly within the scheduling calendar.")
else
alert ("Let's get to it then. Contact Ruth in HR at 576-4208 to schedule an appointment so you can get started.")
///No editing required beyond here/////
//answer only once per browser session (0=no, 1=yes)
var once_per_session=1
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function alertornot(){
if (get_cookie('alerted')==''){
loadalert()
document.cookie="alerted=yes"
}
}
function loadalert(){
alert(alertmessage)
}
if (once_per_session==0)
loadalert()
else
alertornot()
</script>
Your code calls this once per session:
alert(alertmessage)
but the code on top is called on each load of the script.
Moreover - I don't see where alertmessage is defined...
So You probably want to put the code from the top inside the loadalert function resulting in this:
function loadalert(){
var answer=confirm("Click OK if you have been cleared Sutter's HR department to start volunteering.")
if (answer)
alert ("Excellent!! Please select your dates directly within the scheduling calendar.")
else
alert ("Let's get to it then. Contact Ruth in HR at 576-4208 to schedule an appointment so you can get started.")
}
EDIT:
And BTW - start using curly braces. It helps in debug and in understanding where You are. :)