Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying a prompt from javascript Chrome bookmark

I want to create a chrome bookamrk that prompts the user for a value (and then sets that value in a cookie).

I am unable to get the prompt to display. Is there a way to do this?

Current code:

javascript:(function(){var days=window.prompt("Number of days", "d"); var daysInHours=   24*days; document.cookie='clockoffset=PT' + daysInHours + 'H0M';})()
like image 580
Ben Aston Avatar asked Mar 23 '23 00:03

Ben Aston


2 Answers

In chrome, right click on the bookmark bar and choose Add Page

Give the bookmark a name and paste the following code (adjusted for your requirements) into the URL field

javascript:(function(){var site = prompt('Website?');var link = `https://whois.icann.org/en/lookup?name=${site}`;window.location.href = link;})();
like image 67
Ruth Naebeck Avatar answered Apr 02 '23 13:04

Ruth Naebeck


Apparently you cannot run bookmarklets from the Chrome new tab page.

If you want to do something from there then take a look at writing a Chrome Application.

like image 33
Jivings Avatar answered Apr 02 '23 14:04

Jivings