3

I know basically nothing about how to run JavaScript or how it is supposed to work in a bookmark. I just see pages on how it is supposed to work and I can't figure it out!!1

Can I run JavaScript from a bookmark on a phone?
I am using an Android and the chrome app. I edit my bookmark and put examples that I have found online and I don't see it doing anything.

If it is possible, can someone post something that I can literally copy/paste into the bookmark for chrome and see it do something like say hello world?

I have tried javascript:(alert("hello world");) and javascript:(function(){alert("hello world");})

I looked at these links and couldn't figure it out:
https://en.m.wikipedia.org/wiki/Bookmarklet https://stackoverflow.com/a/18872722/5582694

What am I doing wrong???

Chad
  • 111
  • 1
  • 12

1 Answers1

1

I thought we can not use bookmarklets on mobile but after this question, I did a small research and here is the result:

We can set up a bookmarklet on Chrome and then use it on our phone This is the way we can do it:

On your desktop browser, right-click on the bookmarks bar and select "Add Page" or "Add Bookmark" from the menu. In the "Name" field, enter a name for your bookmarklet. In the "URL" field, enter the following code:

javascript:(function() { 
    alert("This is my test bookmarklet")
 })(); 

(This is just a test code and within the function, you can write your own code)

Now in the mobile browser, open up a page, and then within that page type your bookmarklet name(It has a star beside it) and then click it to see the alert test. Here's the result on desktop and mobile: enter image description here

enter image description here

Maziar Rumiani
  • 641
  • 1
  • 4
  • 11
  • What alternatives do you think there are? – Chad Jul 06 '23 at 00:32
  • Oh, wait, I found a solution for it. I edited the original answer so you can use the solution and modify the code the way you want. – Maziar Rumiani Jul 06 '23 at 13:44
  • What is the function/bookmark supposed to do? I don't see anything on the computer or phone. – Chad Jul 07 '23 at 00:03
  • It must show an alert when you are on a page and click on the book mark that you created. I edited the answer and shared a screen shot of the result. – Maziar Rumiani Jul 07 '23 at 00:13
  • Oh, ok, on my computer, I had to be on a page for the bookmark to show the alert. I still don't see anything on the phone. – Chad Jul 07 '23 at 00:28
  • Now I added a picture from my phone too, I hope it helps. – Maziar Rumiani Jul 07 '23 at 00:38
  • How do you get that window on the left side of the bottom screen shot? – Chad Jul 07 '23 at 01:22
  • Oh, I see now. I am not exactly sure what I was doing wrong before. I guess I was just hitting enter on my phone instead of scrolling down and tapping the starred bookmark in the auto populated results. – Chad Jul 07 '23 at 01:31