function as google chrome bookmark

落爺英雄遲暮 提交于 2019-11-28 03:32:25

You can do this using a bookmarklet. A bookmarklet is a bookmark with a URI starting with the pseudo-protocol javascript: followed by URI-encoded JavaScript code. When you trigger the bookmark, browser will run the code in the context of the current page. So you'd go to that page, then use that bookmarklet to fill in your standard information, and there you go.

For example, here's a bookmarklet that, when run, will look for an element with the id someElement on the page and, if found, assign "some value" to its value property:

javascript:(function(){var d=document,e=d.getElementById("someElement");e.value="some value";})();

This bookmarklet creator will come in handy to squish your JavaScript into one line: http://mrcoles.com/bookmarklet/

javascript : { document.getElementById('PlateNo').value='0815';document.getElementById('AppRef').value='013007';document.getElementById('VehicleReg').value='MX53 YMD'; void(0) }
Matthias S

Here is an example of one that lets you edit the webpage like a document.

javascript:document.body.contentEditable = 'true'; document.designMode='on'; void 0

You can use prompts and alerts and confirm windows, and I created a game, kind of. It's not that clean though. Here's the javascript-code:

To the editor: there needs to be a "javascript:" at the start for it to work btw

javascript: 
var totalClicks = 0;
for (var i = 0; i < 1000000; i++){
    var message1 = prompt("Clicker Game!\nClicks: "+totalClicks,"remove this text to end the game");
    totalClicks++;
    if (message1 !== "remove this text to end the game"){
        i = Math.Infinity;
    }
}
alert("Thanks for playing my game!\nClicks: "+totalClicks)

For Mozilla use like as

javascript:function myFun(){
var d=document;
var e=d.getElementById("someElement");
var e.value="some value";
}myFun();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!