jakx12 0 Junior Poster

Hey everyone,

I am new to js and am writing a bookmarklet.

For some reason cookies are not working at all. I have tried numerous setCookie, delCookie etc functions and none work, so I am using the simplest form of setting a cookie and it still ceases to work. Here is my code

(function(){

	// the minimum version of jQuery we want
	var v = "1.3.2";

	// check prior inclusion and version
	if (window.jQuery === undefined || window.jQuery.fn.jquery < v) {
		var done = false;
		var script = document.createElement("script");
		script.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
		script.onload = script.onreadystatechange = function(){
			if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
				done = true;
				initMyBookmarklet();
			}
		};
		document.getElementsByTagName("head")[0].appendChild(script);
	} else {
		initMyBookmarklet();
	}

	function initMyBookmarklet() {
		(window.myBookmarklet = function() {
			count = 0;
		    $('body').append("<div id='notes' style='position: absolute; bottom: 20px; right: 20px; overflow: auto;'></div>");
		    document.cookie = "asd"+"="+"asd;";
		    alert(document.cookie);
			function getSelText() 
			{
				var SelText = '';
				if (window.getSelection) {
					SelText = window.getSelection();
				} else if (document.getSelection) {
					SelText = document.getSelection();
				} else if (document.selection) {
					SelText = document.selection.createRange().text;
				}
				return SelText;
			}
			
			document.onkeydown = function(e) 
			{ 
				if (e.keyCode == 27) 
					document.location.reload(true); 
			} 
			
			document.onclick = function(e) 
			{ 
				if (e.altKey)
				{
					var text = getSelText();
					if (text == "")
						alert("You must select some text!");
					else
					{
						 $('#notes').append( "<div id='note-" + count + "' style='background-color: green; color: black; padding: 10px; margin-bottom: 10px; text-align:left; width: 400px;'><div id='note-"+ count +"-buttons' style='float:right'><a href='javascript:;' id='note-" + count +"-save'>Save</a> | <a href='javascript:void(0);' id='note-" + count +"-delete'>Delete</a></div><br/><i>" + text + "</i></div>").hide().fadeIn(2000);
						 
						  $('#note-' + count + '-delete').click(function() {
							var destroy = confirm("Are you sure you want to delete this note?");
							if (destroy)
							{
								var noteNum = $(this).attr('id').split("-")[1];
								$('#note-' + noteNum).remove();
								$('#note-' + noteNum + "-buttons").remove();
								$('#note-' + noteNum = "-delete").remove();
							}
							
						 }); 
						  $('#note-' + count + '-save').click(function() {
							$('#note-'+$(this).attr('id').split("-")[1]).css("background-color", "green");
						 }); 
						
						count++;
					}
				}
			}
			

			
			
			//alert(getSelText());
		})();
	}

})();

Whats wrong? Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.