Search code examples
javascriptmobilebookmarks

Can I run JavaScript from a mobile bookmark


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???


Solution

  • 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