Iep, i have a problem, its the first time that im working with cookies and i was trying to save them.
The question is that only the 2 first values are saved, in this case "nombre" and "tuValor". If i do "alert(document.cookie)" the other values dont apear.
<script type="text/javascript">
function guardar() {
Nombre = "Empire";
tuValor = "F"+food;
tuValor2 = "w"+wood;
caduca = "31 Dec 2020 23:59:59 GMT";
document.cookie = Nombre+"="+tuValor+tuValor2+"expire= "+caduca ;
}
</script>
You forgot the semicolon before expire.
It goes like this:
document.cookie="my_cookie=empireWh4t3v3r;expires=Thu, 23 Apr 2020 15:37:15 GMT;"
Related
I am trying to remove a cookie from IE when the page loads.
The Cookie is no longer in use and needs to be removed, I have tried setting the expiry date as follows:
function seta() {
document.cookie = "CookieControl=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
}
function deleteCookie(name) {
setCookie('CookieControl', "", {
'max-age': -1
})
}
If I create the cookie I can delete it.
$j1.cookie('CookieControl', 'hrd', { expires: 365, path: '/' });)
How do I delete an existing cookie in IE 11?
In working with timestamps, moment.js, and the provided example of implementation by founddrama, I added the following to my html site:
<span id="then" data-date="Aug 22 2018 11:33:00 GMT-0700 (PDT)"></span>
<script>
$(document).ready(function(){
var then = $('#then'),
date = moment(new Date(then.attr('data-date'))),
update = function(){
then.html(date.fromNow());
};
update();
setInterval(update, 60000);
});
</script>
The output result was successful.
I would, however, like to add multiple timestamps.
In order to successfully render, I coded in this manner:
<span id="then" data-date="Aug 18 2018 07:33:00 GMT-0700 (PDT)"></span>
<span id="then1" data-date1="Aug 3 2018 16:33:00 GMT-0700 (PDT)"></span>
<script>
$(document).ready(function(){
var then = $('#then'),
date = moment(new Date(then.attr('data-date'))),
update = function(){
then.html(date.fromNow());
};
update();
setInterval(update, 60000);
});
</script>
<script>
$(document).ready(function(){
var then = $('#then1'),
date = moment(new Date(then.attr('data-date1'))),
update = function(){
then.html(date.fromNow());
};
update();
setInterval(update, 60000);
});
</script>
I am looking for a clean, concise way to properly group the javascript code, and place within one script block, instead of two.
This will find all DOM elements with the class then and then find each of their data-date attributes and set their inner HTML to a moment.js object.
<span class="then" data-date="Aug 22 2018 11:33:00 GMT-0700 (PDT)"></span>
<span class="then" data-date="July 15 2018 9:33:00 GMT-0700 (PDT)"></span>
<script>
$(document).ready(function(){
var dates = $('.then');
$.each(dates, function(){
var date = moment(new Date($(this).attr('data-date')))
$(this).html(date.fromNow());
})
});
</script>
First provide the class name to span elements.
Then parse to each span elements.
Make data attribute common i.e. data-date and not different for each span.
Then parse through all the span and append the html.
<span class="then" data-date="Aug 18 2018 07:33:00 GMT-0700 (PDT)"></span>
<span class="then" data-date="Aug 3 2018 16:33:00 GMT-0700 (PDT)"></span>
<script>
$(document).ready(function(){
$('.then').each(function(i) {
var $this = $(this);
var date = moment(new Date($this.attr('data-date')));
var update = function() {
$this.html(date.fromNow());
};
update();
setInterval(update, 60000);
});
});
</script>
I have a wordpress website where you click on a div, and a mailchimp popup form pops up. One issue is, mailchimp stores a cookie to make sure the popup is only done once. But since I'm now doing it on a click, I want to get rid of that cookie.
This is my code:
var mailchimpConfig = {
baseUrl: 'mc.us17.list-manage.com',
uuid: '1356322e2......rest of my code',
lid: '36776d...rest of my code'
};
// No edits below this line are required
var chimpPopupLoader = document.createElement("script");
chimpPopupLoader.src = '//s3.amazonaws.com/downloads.mailchimp.com/js/signup-forms/popup/embed.js';
chimpPopupLoader.setAttribute('data-dojo-config', 'usePlainJson: true, isDebug: false');
var chimpPopup = document.createElement("script");
chimpPopup.appendChild(document.createTextNode('require(["mojo/signup-forms/Loader"], function (L) { L.start({"baseUrl": "' + mailchimpConfig.baseUrl + '", "uuid": "' + mailchimpConfig.uuid + '", "lid": "' + mailchimpConfig.lid + '"})});'));
jQuery(function ($) {
document.body.appendChild(chimpPopupLoader);
jQuery(".coming-soon").on("click", function () {
alert("Hello");
document.body.appendChild(chimpPopup);
document.cookie = 'MCEvilPopupClosed=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;';
});
});
So after searching the internet, I found that everyone used this code to remove the cookie.
document.cookie = 'MCEvilPopupClosed=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;';
This issue is, it's not working for me. I've done all testing in incognito and can only get the pop up to work once.
The cookie's name is MCPopupClosed rather than MCEvilPopupClosed. I'm not sure why, but MailChimp must have changed it at some point.
There's also another cookie called MCPopupSubscribed, which is set if the user subscribes instead of closing the popup with the 'X' button. If you want the popup to display even if the user has subscribed, you'll want to clear that cookie as well.
Clearing those two cookies will only make it work once after the page loads, though. I came across this code while looking into the issue, and it works fine if you put the require in the click function instead of a script tag. Doing this also prevents having to remove the script tags generated by the appendChild function every time the element is clicked.
So your updated code looks like this:
var mailchimpConfig = {
baseUrl: 'mc.us17.list-manage.com',
uuid: '1356322e2......rest of my code',
lid: '36776d...rest of my code'
};
// No edits below this line are required
var chimpPopupLoader = document.createElement("script");
chimpPopupLoader.src = '//s3.amazonaws.com/downloads.mailchimp.com/js/signup-forms/popup/embed.js';
chimpPopupLoader.setAttribute('data-dojo-config', 'usePlainJson: true, isDebug: false');
jQuery(function ($) {
document.body.appendChild(chimpPopupLoader);
jQuery(".coming-soon").on("click", function () {
require(["mojo/signup-forms/Loader"], function (L) { L.start({"baseUrl": mailchimpConfig.baseUrl, "uuid": mailchimpConfig.uuid, "lid": mailchimpConfig.lid})});
document.cookie = 'MCPopupClosed=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;';
document.cookie = 'MCPopupSubscribed=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;';
});
});
you missed a cookie:
document.cookie = "MCEvilPopupClosed=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
I've just corrected the exact same problem.
Hope this helps,
P.
This question already has an answer here:
I want to split a string and want to put in the dropdown list in html, javascript [closed]
(1 answer)
Closed 8 years ago.
strPropertyEvents=20 Aug 2014-New Activity 1, 21 Aug 2014-gfdbfjdb ,21 Aug 2014-anubhav, 24 ug 2014-hjdf
Basically In strPropertyEvents it is stored in the form of string but I want to split this string in such a manner that where there is a comma , it splits down there and the output is in a dropdown list as
<script type="text/javascript">
$('#hiddenActivityDate').val('#strPropertyEvents');
alert($('#hiddenActivityDate').val());
var strList = hiddenActivityDate.split(',');
console.log(strList);
$.each(strList,function(index,val){
$("#ProgramList").append('<option>'+val+'</option>');
});
</script>
But the code is not working. Could you please help me out what is the mistake either in fiddle or anywhere.
I don't find the definition of hiddenActivityDate
<script type="text/javascript">
$('#hiddenActivityDate').val('#strPropertyEvents');
var hiddenActivityDate = $('#hiddenActivityDate').val();
var strList = hiddenActivityDate.split(',');
console.log(strList);
$.each(strList,function(index,val){
$("#ProgramList").append('<option>'+val+'</option>');
});
</script>
I'm not quite sure where you get the string from, but I've added a working example where the string is declared at the top, as well as in a hidden input field.
<script type="text/javascript">
$(document).ready(function(){
var strPropertyEvents="20 Aug 2014-New Activity 1, 21 Aug 2014-gfdbfjdb ,21 Aug 2014-anubhav, 24 ug 2014-hjdf";
$('#hiddenActivityDate').val(strPropertyEvents);
var strList = strPropertyEvents.split(',');
console.log(strList);
$.each(strList,function(index,val){
$("#ProgramList").append('<option>'+val+'</option>');
});
});
</script>
<input id="hiddenActivityDate" type="hidden" />
<select id="ProgramList"></select>
fiddle
I want to format a timestamp such as 1406270888 to Sunday, July 25, 2014 12:48:08 PM in a WebView on android device.
My Javascript code is as follows:
<script>
var chatTimestamp=parseInt(1406270888);
var date = new Date(chatTimestamp*1000);
var localTime =date.toLocaleDateString()+ " "+ date.toLocaleTimeString();
document.getElementById("demo").innerHTML = localTime;
</script>
But the output I get is as follows:
Sunday, July 25, 2014 12:48:08
So Basically AM PM is missing.
Source: http://www.w3schools.com/jsref/jsref_tolocaletimestring.asp
Any help is appreciated.
Thanks
Try this script
<script type="text/javascript">
var chatTimestamp=parseInt(1406270888);
var date = new Date(chatTimestamp*1000);
document.write(date.toString());
document.write(date.getFullYear()+'-'+date.getMonth()+'-'+date.getDate()+' '+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds());
</script>