简体   繁体   English

如何将javascript小书签设置为主页?

[英]How can I set a javascript bookmarklet as a homepage?

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 . 我可以毫无问题地将其复制并粘贴到Chrome的网址栏中,打开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. 但是,如果我将其粘贴到Chrome的homepage部分中,则单击home按钮时没有任何反应。

Why doesn't Chrome want to let me use my Javascript as a homepage? Chrome为什么不想让我将Javascript用作首页? How can I use this javascript bookmarklet as a homepage so that it runs every time I open Chrome? 如何使用此javascript小书签作为主页,以便每次打开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. 我希望一种解决方案是将其嵌入到外部HTML页面中,但这似乎是不必要的,而且我也不清楚如何调用someJS()

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. 编辑:进一步的调查显示,实际上,此Javascript根本无法使用-一旦调用location.href,就不会再运行任何JavaScript。 Moreover, Chrome doesn't let you run javascript from the URL from its start page - only from a webpage. 而且,Chrome不允许您从其起始页的URL中运行javascript,而只能从网页中运行。

Chrome上默认禁用地址栏中的JavaScript。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM