如何将 javascript 书签设置为主页?
我编写了一个小书签,我想将其设置为我的主页。它很简单,看起来像这样:
javascript:location.href='http://somesitetoload.com';someJS();
我可以毫无问题地将其复制并粘贴到 Chrome 的地址栏中,并且打开 somepagetoload.com
时它似乎运行良好。我也可以毫无问题地将它作为书签调用。
但是,如果我将其粘贴到 Chrome 的 homepage
部分,则当我单击 home
按钮时什么也不会发生。
为什么 Chrome 不想让我使用 Javascript 作为主页?如何使用这个 javascript 书签作为主页,以便每次打开 Chrome 时它都会运行?
我希望一种解决方案是将其嵌入到外部 HTML 页面中,但这似乎没有必要,而且我也不清楚如何调用 someJS()
。
编辑:进一步的调查表明,事实上,这个 Javascript 根本不起作用——一旦调用 location.href,就不会再运行任何 JavaScript。此外,Chrome 不允许您从其起始页的 URL 运行 javascript - 只能从网页运行。
I've written a bookmarklet that I'd like to set as my homepage. It's simple, and looks like this:
javascript:location.href='http://somesitetoload.com';someJS();
I can copy and paste this into Chrome's URL bar without a problem, and it seems to run fine, opening somepagetoload.com
. I can invoke it as a bookmarklet without a problem, too.
However, if I stick this into the homepage
section of Chrome, nothing happens when I click the home
button.
Why doesn't Chrome want to let me use my Javascript as a homepage? How can I use this javascript bookmarklet as a homepage so that it runs every time I open Chrome?
I expect one solution is to embed it in an external HTML page, but that seems unnecessary, and I'm also not clear on how someJS()
would ever be invoked.
EDIT: Further investigation has revealed that, in fact, this Javascript won't work at all -- once location.href is invoked, no further javascript will run. Moreover, Chrome doesn't let you run javascript from the URL from its start page - only from a webpage.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,Chrome 上地址栏中的 JavaScript 处于禁用状态。
JavaScript in the address bar is disabled by default on Chrome.