[英]How to change a site background color using the browser's address bar?
When I type in the address bar in Google Chrome or any other browser: 当我在Google Chrome浏览器或任何其他浏览器中输入地址栏时:
javascript:alert("hello");
It works, but 它有效,但是
javascript:document.body.style.background="Red";
doesn't. 没有。 Why is that?
这是为什么? How to use the address bar to change the background color?
如何使用地址栏更改背景颜色?
Add ;void 0
after the bookmarklet. 在小书签后添加
;void 0
。 When the code has a non- undefine
value, the page unloads, and the return value is printed. 当代码的值
undefine
,页面将被卸载,并显示返回值。
A common way to write bookmarklets is: 编写书签的常见方法是:
javascript:(function(){ ... code ... })();
undefined
, so the page will not unload. undefined
,因此页面不会卸载。 Note that in the latest versions of modern browsers (FF, Chrome), many objects are not available through the javascript:
-URL in the location bar . 请注意,在最新版本的现代浏览器(FF,Chrome)中,许多对象无法通过
javascript:
位置栏中的 URL来使用。
You need to activate this ability in your Chrome configuration. 您需要在Chrome配置中激活此功能。 It's turned off by default.
默认情况下它是关闭的。
之所以使用XMLForDummies,是因为无法从该位置访问文档对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.