How to prevent bookmarklet from loading its result?

不问归期 提交于 2019-12-02 12:25:41

The accepted way these days is to wrap your code in an "immediately invoked function expression" like this

(function(){ /*your code */})();

This is better than adding void(0); at the end because wrapping your code in a function prevents conflicts between named variable and function in your bookmarklet and in those in the scope of the parent HTML document.

In other words, if you run your bookmarklet as it is now on a web page that uses JavaScript code with an already existing variable "description", you could create problems.

Add void(0); at the end of it.

javascript:var%20description;var%20metas=document.getElementsByTagName('meta');for(var%20x=0,y=metas.length;x<y;x++){if(metas[x].name.toLowerCase()=="description"){description=metas[x];}}prompt("Meta%20Description",description.content);void(0);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!