Javascript bookmarklet that creates an alert box and allows you insert a text. This text…
- User
Javascript bookmarklet that creates an alert box and allows you insert a text. This text will be saved as a cookie called "session".
- Assistant
You can create a JavaScript bookmarklet that prompts the user to input text, and then saves that text as a cookie named "session". Here’s how you can do this:
- Create a new bookmark in your web browser.
- For the URL of the bookmark, enter the following JavaScript code:
javascript:(function() { var userInput = prompt("Please enter text to save as a cookie:"); if (userInput !== null) { document.cookie = "session=" + encodeURIComponent(userInput) + "; path=/; expires=Fri, 31 Dec 9999 23:59:59 GMT"; alert("Your text has been saved as a cookie named 'session'."); } else { alert("No text entered. Cookie not saved."); } })();How It Works:
- The
promptfunction asks the user to enter some text. - If the user provides input, it saves the input as a cookie named "session".
- User
one line, and no if else.
- Assistant
Certainly! Here's a one-liner JavaScript bookmarklet that prompts for input, saves it as a cookie named "session", and always proceeds without any
if...elsestatements:javascript:(function(){document.cookie="session=" + encodeURIComponent(prompt("Please enter text to save as a cookie:")) + "; path=/; expires=Fri, 31 Dec 9999 23:59:59 GMT";})();To Use It:
- Create a new bookmark in your browser.
- Set the URL of the bookmark to the code above.
- Click the bookmark while on any webpage to prompt for input and save the cookie immediately.
This code will execute the prompt, and regardless of whether the user clicks "OK" or cancels, it will attempt to set the cookie with the return value of
prompt(). If the user cancels, an empty cookie will be set. - User
no path or expires stuff, just save the cookie as session
- Assistant
Sure! Here's a simplified one-liner JavaScript bookmarklet that saves the input directly as a cookie named "session" without specifying the
pathorexpiresattributes:javascript:(function(){document.cookie="session=" + encodeURIComponent(prompt("Please enter text to save as a cookie:"));})();To Use It:
- Create a new bookmark in your browser.
- Set the URL of the bookmark to the code above.
- Click the bookmark while on any webpage to prompt for input and save the cookie.
This sets the cookie with the default attributes, meaning that it will apply to the current page and session.
- User
no encode uri
- Assistant
Certainly! Here's a one-liner JavaScript bookmarklet that prompts for input and saves it as a cookie named "session" without any URL encoding or additional attributes:
javascript:(function(){document.cookie="session=" + prompt("Please enter text to save as a cookie:");})();To Use It:
- Create a new bookmark in your browser.
- Set the URL of the bookmark to the code above.
- Click the bookmark while on any webpage to prompt for input and save the cookie.
This will save the entered text directly as a cookie named "session" without any encoding.