JavaScript - Check The Existance Of Remote A Cookie
Is there any way to check if exists a cookie from a domain2 in domain1?
The purpose here is if the cookie from domain 2 exists then do an action in domain 1. For example: Erase cookie or do an action. Similar TutorialsHello, through a javascript injection im trying to find out if a cookie exists on my computer. Here's the code I inject: Code: javascript: if (document.cookie.indexOf('_idp_session') != -1) alert('cookie is here'); else alert('cookie is not here'); and when visiting the options of my browser, I can locate the cookie, and i can see its there. Nevertheless my script keeps telling me its not there.. what am i doing wrong? Hello everyone. I am trying to put together a browser based game which uses javascript and cookies, and am looking for help with one of it's functions. I need a script which checks a cookie value, then displays a certain image, depending on what that value is. So, if the value is 50, it displays one, if it's 60 it display another one etc. What script would I use? Hello, i wrote this code to open a page if doesn't exist a cookie but it doesn't open the page do you know where I wrong? Thank you ! Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> HTML </title> </head> <body> <script type="text/javascript"> function CookieLeggi(CookieNome) { if (CookieNome.length==0) return null; var PosizioneIniziale = document.cookie.indexOf(CookieNome+"="); if (PosizioneIniziale == -1) return null; PosizioneIniziale += CookieNome.length+1; var PosizioneFinale = document.cookie.indexOf(";",PosizioneIniziale); if (PosizioneFinale == -1) PosizioneFinale = document.cookie.length; return unescape(document.cookie.substring(PosizioneIniziale,PosizioneFinale)); } function CookieScrivi(name,value,expiresUdM,expires,path,domain,secure) { if (!name || !value) { return false } if ((expiresUdM && expires) && (expiresUdM!='GMT')) { var ExpiresMillisec = ExpiresDate = Oggi = new Date(); switch (expiresUdM) { // calcola i JS-millisecondi del momento di scadenza case "anni": ExpiresMillisec=Oggi.getTime()+expires*365*24*60*60*1000; break; case "mesi": ExpiresMillisec=Oggi.getTime()+expires*31*24*60*60*1000; break; case "giorni": ExpiresMillisec=Oggi.getTime()+expires*24*60*60*1000; break; case "ore": ExpiresMillisec=Oggi.getTime()+expires*60*60*1000; break; case "minuti": ExpiresMillisec=Oggi.getTime()+expires*60*1000; break; case "secondi": ExpiresMillisec=Oggi.getTime()+expires*1000; break; default: ExpiresMillisec=Oggi.getTime()+expires; } ExpiresDate.setTime(ExpiresMillisec); expires = ExpiresDate.toGMTString(); } secure = (secure=="1" || secure==1 || secure=="secure") ? 1 : ""; document.cookie = name + "=" +escape(value) + ( (expiresUdM && expires) ? "; expires=" + expires : "") + ( (path) ? "; path=" + path : "") + ( (domain) ? "; domain=" + domain : "") + ( (secure) ? "; secure" : ""); if (CookieLeggi(name)==null && secure!=1) { return false; } else { return true; } } </script> <script type="text/javascript"> if (CookieLeggi(liveads) == "null") { window.open("http://www.google.com", "Google"); CookieScrivi(liveads, adsm, ore, 12, /, .localhost, 1); } else { break; } </script> </body> </html> Hi everyone, I am using a jQuery cookie script to set the cookie of some elements on my website. One of the problems is that I need the cookie to not expire after one day, I need it to expire after a while (I'm going to start off with a year). Here's my script, the red part is what I've been editing. Code: /** * Cookie plugin * * Copyright (c) 2006 Klaus Hartl (stilbuero.de) * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * */ /** * Create a cookie with the given name and value and other optional parameters. * * @example $.cookie('the_cookie', 'the_value'); * @desc Set the value of a cookie. * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secu true }); * @desc Create a cookie with all available options. * @example $.cookie('the_cookie', 'the_value'); * @desc Create a session cookie. * @example $.cookie('the_cookie', null); * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain * used when the cookie was set. * * @param String name The name of the cookie. * @param String value The value of the cookie. * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. * If a negative value is specified (e.g. a date in the past), the cookie will be deleted. * If set to null or omitted, the cookie will be a session cookie and will not be retained * when the the browser exits. * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will * require a secure protocol (like HTTPS). * @type undefined * * @name $.cookie * @cat Plugins/Cookie * @author Klaus Hartl/klaus.hartl@stilbuero.de */ /** * Get the value of a cookie with the given name. * * @example $.cookie('the_cookie'); * @desc Get the value of a cookie. * * @param String name The name of the cookie. * @return The value of the cookie. * @type String * * @name $.cookie * @cat Plugins/Cookie * @author Klaus Hartl/klaus.hartl@stilbuero.de */ jQuery.cookie = function(name, value, options) { if (typeof value != 'undefined') { // name and value given, set cookie options = options || {}; if (value === null) { value = ''; options.expires = -1; } var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { var date; if (typeof options.expires == 'number') { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000 * 365)); } else { date = options.expires; } expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE } // CAUTION: Needed to parenthesize options.path and options.domain // in the following expressions, otherwise they evaluate to undefined // in the packed version for some reason... var path = options.path ? '; path=' + (options.path) : ''; var domain = options.domain ? '; domain=' + (options.domain) : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); } else { // only name given, get cookie var cookieValue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = jQuery.trim(cookies[i]); // Does this cookie string begin with the name we want? if (cookie.substring(0, name.length + 1) == (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } }; On this webpage http://www.corkdiscos.com/testimonials.html i have a like button. when a user clicks like a comment box appears. when i unlike the button the comment box disappears this is ok but when a user has already liked the facebook page and comes to my webpage the comment box does not show. so im looking for a piece of javascript to check if a user has like the button on my page and if so to show the comment box. please check my source code of the website http://www.corkdiscos.com/testimonials.html to see what i have so far. any help would be greatly appreciated Hi guys. I'm working a bunch of pre existing code on a CMS. Just after a quick fix. Doing a show/hide thing on a particular div somewhere on the page depending if a checkbox is ticked or not. Currently there is 3 checkboxes that are dynamically added through the CMS. Here's simplified version of the form: Code: <form id="simplesearch" name="simplesearch"> <input type="checkbox" onclick='showhidefield(this.value)' name="meta_data_array_search_criteria[custom_profile_type][]" value="5" class="input-checkboxes" /> <input type="checkbox" onclick='showhidefield(this.value)' name="meta_data_array_search_criteria[custom_profile_type][]" value="4" class="input-checkboxes" /> </form> And here's the javascript I was playing with. Code: function showhidefield(id) { if(document.simplesearch.meta_data_array_search_criteria[custom_profile_type][''].checked) { document.getElementById("profile_fields_wrapper_" + id).style.visibility = "visible"; } else { document.getElementById("profile_fields_wrapper_" + id).style.visibility = "hidden"; } } Problem I'm having is how do i do a check to see if those checkboxes are checked in the javascript with those name arrays? How do i separate them? 'm guessing I have to loop through them or something?Hopefully that make senses - it's late here and I'm losing the plot Any pointers would be gratefully welcomed Hi, I am hosting my website in free server (freehostia.com) and i am using joomla1.5 . I want to parse RSS from my other websites. Joomla does it with its modules. But the server do not allow outbound HTTP request, hence i had use rss-to-javascript website to parse RSS feeds. It parses well but there is its advertisement below the feed (which i think is nonsense). The link it provides is in the format of <script src="http://somethin.com/somdfile.php?parse=.."></script> when i put the link in my browser i see following document.write("string of my parsed xml file with advertisement at end"); What i want to do is get the sting of above line and edit it to chop off the end advertisement. if there was any method to load that output sting in any variable, the task would had been completed. If anybody knows how to do it, please help me. I have a google blogger site on which I want to run a PHP script. The problem is that blogger doesn't have a PHP interpreter. So I was thinking, can I run the php file on a remote server that supports php, and load the result in a div in blogger? Thx! Hi, Im trying to load a remote script but only if a statement is true.. Code: <script type="text/javascript"> var width=screen.width; if (width>1023); { // load remote script } </script> How would I go about this? And will it work if the script in php? Thank youu! EDIT: I realise its probably not the best practice but at the moment im having to use Code: <script language="javascript"> window.location.href = "index2.php?width=" + screen.width; </script> and on index2.php Code: <?php $res=$_GET['width']; if ($res > 1024) { include("header.php"); } ?> Hello, I'm building a very simple app that relies on a remote server. I will use this app on many websites, so I decided to store it on one server (I have control of the remote server in question). I need to make sure that this server is up and running, so in the case it's not I can use a fallback. Would it be a client-side approach? A server-side approach? My guess is to use a js snippet to do the job. If I'm correct, I'll probably use jquery to perfom the task. Regards, -jj. If I use a window opener to open a new window, is there a way to detect that the new window is finished loading before carrying out some other directive in the opener window? Can I access the remote window's onload event from the opener window? I need to know that the website has loaded before moving to the next page. something like: remoteWindow.onload = goToPage(url); Is this even possible? HI I'm new to tinymce. I'm using tinymce with jquery validate with remote Methods. (Remote Methods: http://docs.jquery.com/Plugins/Valid...Methods/remote) I'm using jquery validate to check if email address already has been enter into the database, once it check the email hasn't been entered. It then enter the email with the tinymce textarea. Right now the email address gets enter but tinymce textarea is undefined. I understand I have to uses the var content = tinyMCE.get (editor_id);, but its still enter as undefined, here is my code below: Code: <html> <head> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/jquery.validate.js"></script> <script type="text/javascript" src="js/tiny_mce.js"></script> <script type="text/javascript"> tinyMCE.init({ // Location of TinyMCE script // General options mode : "textareas", elements : "editor_id", theme : "advanced", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "bottom", theme_advanced_resizing : true, content_css : "css/content.css", }); <script type="text/javascript"> $(document).ready(function(){ var validator = $("#myform").validate({ rules: { email: { required: true, minlength: 5, remote: { url: "test.php", type: "post", data: { dataType: 'json', email: function() { return $("#email").val(); }, content: function() { return $("content").val(); } }, }, } }, messages: { sub_name: { required: "Please enter a email address", minlength: "Your email addressmust be at least 5 characters long", remote: jQuery.format("Sorry but '{0}' has already been added. Please try again.") } }); }); </script> </head> <body> <form id="myform" action="" method="post"> <input type="text" name="email" id="email" size="15"/> <textarea id="editor_id" name="editor_id" rows="15" cols="80" ></textarea> <input type="submit" value="Submit"/> </form> Where do I added? Code: var content = tinyMCE.get('editor_id'); content = escape(content.getContent()); content = content.replace("+", "%2B"); content = content.replace("/", "%2F"); thanks I have discovered a XSS vuln in a website and I'd like to use this as a cookie grabber. If you can help, <removed>.
Hi im kind of new to cookies in Javascript. But after reading a few tutorials on how the work I started to wonder. Is it possible to grab a cookie made by my phpbb forum? I would love to be able to login on my site using my phpbb forum cookies. Anway if this is a bad idea ore won't work for any reason plz let me know. Thanks Hi im new to working with cookies so would appreaciate a little help I using the w3c tuturial as a template so heres a link so you can see what im trying to do http://www.w3schools.com/JS/js_cookies.asp Code: function getCookie(c_name) { var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i<ARRcookies.length;i++) { x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); x=x.replace(/^\s+|\s+$/g,""); if (x==c_name) { return unescape(y); } } } function setCookie(c_name,value,exdays) { var exdate=new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); document.cookie=c_name + "=" + c_value; } function checkCookie(username) { var username=getCookie("username"); if (username!=null && username!="") { document.getElementById("feedback").innerHTML = " last time you scored " + username); setCookie("username",username,365); } else { if (username=null || username="") { setCookie("username",username,365); } } } I kept the variable names the same so you can follow and I don't confuse myself and make things more complected while im trying to debug it. Some extra information. checkcookie is been given a variable it is just a simple number. Im making a questionnaire which is done but I wont the top of the page to tell the user how much they scored last or tell them this is their first time trying it. The variable being passed to check cookie is their score . at the moment when I click the submit button nothing happens. Where it should trigger a score calculating function which should then call the checkcookie function while passing the score it calculated. I would love if someone can point me in the right direction or help me correct it or atleast explain to me whats going wrong. Thanks and a lots of appreciation if anyone can spare the time Hello. I am a neewb, so bare with me. This code is not working correctly for some reason. If I use it in Internet Explorer it will work, but only if you bring up the history in the url tab. You cannot refresh it for whatever reason. so basically it works in Explorer but no refresh. The big problem is Mozilla. I will not work at all. I have all of the cookies set for third party, remember last visit and so on. It will only display the welcome page for first time visitor. Then it will show the subsequent page, however it will not increment the count +1. I am not sure what is going on here, Explorer works, but with no refresh, and Mozilla does not really work at all? Here is my script currently: <script type="text/javascript"> /* <![CDATA[ */ function hitMySite() { var lastDate = new Date(); lastDate.setMonth(lastDate.getMonth()); var dateString = (lastDate.getMonth() + 1) + "/" + lastDate.getDate() + "/" + lastDate.getFullYear(); if (document.cookie != "") { counter = document.cookie.split("=")[1]; counter = parseInt(counter) + 1; date = document.cookie.split(":")[2]; var expireDate = new Date(); expireDate.setMonth(expireDate.getMonth() + 12); document.cookie = "counter=" + counter + ":date:" + dateString + ";expires=" + expireDate.toGMTString(); document.write("<h1>You last visited this page on: " + date + "<br />You have been to this page " + counter + " times.</h1>"); } else { document.write("<h1>Welcome to my Web site! This is your first visit here so be sure to bookmark my page!</h1>"); var counter = 1; var expireDate = new Date(); expireDate.setMonth(expireDate.getMonth() + 12); document.cookie = "counter=" + counter + ":date:" + dateString + ";expires=" + expireDate.toGMTString(); } } /* ]]> */ </script> </head> <body onload="hitMySite()"> </body> </html> Hi everyone! Got a quick (cookie) question. I looked on the internet for some cookie scripts (redirect ones), but unfortunately haven't been too lucky with these. What I want to do is the following: When the cookie is not found it goes to my main page, for example: "www.anynamehere.com" On the main page I can select where I want to go - 'Contacts', 'News', 'Forums' and so on. The main page has a drop down list with these options, each option has it's own link. When I click on 'continue' and go to the specific link (ex. www.anynamehere.com/contacts.html) it should remember my selection, so next time I log into www.anynamehere.com it's automatically will take me to contacts.html. I will not see the main page anymore. Now, if from the contacts page I select 'News' and go to www.anynamehere.com/news.html it has to remember that link as well. So if I close my browser and then reopen it, it should take me to www.anyname.com/news.html. I hope that makes sense. If anyone can give me any pointers I would greatly appreciate it. Maybe there is a script like that available online, I just wasn't lucky enough to find one. Thank you in advance! Hello, I was wondering if someone could tell me how to change the cookie on this piece of code? I'd like it to put a different cookie for each page it's used on. Any help would be appreciated. Thanks! Code: /* * COOKIE FUNCTIONS */ function createCookie(name, value, days) { if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); var expires = "; expires=" + date.toGMTString(); } else var expires = ""; document.cookie = name + "=" + value + expires + "; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; } function eraseCookie(name) { createCookie(name, "", -1); } /* * END COOKIE FUNCTIONS Hello I have below script i need add cookie to it . disable script untill cookie is not expired can you please help me <script language=javascript type="text/javascript"> <!-- Hide script from old browsers //new window script function jshow() {window.open("http://www.google.com","blank")} // End hiding script from old browsers --> </script> |