-2

How can I add a javascript file to the bookmark bar so that when I click on that file that is set in the bookmark bar then the javascript gets executed on the current webpage. Like if I had written a javascript file to run on a webpage and I want to set it to the bookmark bar of chrome and when I click on it then the javascript gets executed on the current webpage

if this is the code so how can i add it

let added = document.getElementById('name');
let text = 'Example Singh';
added.value = text;

now I want to add this code to a website in the bookmark bar of google chrome

2 Answers2

1

You can use a Bookmarklet. It is a bookmark that runs a small piece of JavaScript.

So if you add a bookmark to your bookmarks and then set the URL to contain URL encoded JavaScript prefixed with javascript:, when you click the bookmark it will run the bookmark(let)'s JS.

Given your code above you should set a bookmarklet with the following "URL"

javascript:document.getElementById('name').value='Example Singh';

More information about bookmarklets can be found here

phuzi
  • 12,078
  • 3
  • 26
  • 50
0

On Chrome without extensions:

  1. create any bookmark
  2. right click on it - Edit...
  3. replace url field with javascript javascript:alert('hello');
  4. pressing it executes javascript on currently opened page

To toggle bookmarks bar on a page, use ctrl + shift + B

Max
  • 4,473
  • 1
  • 16
  • 18