用于获取当前网站地址但不包含 http:// 的书签
前几天你非常乐于助人。现在我有另一个问题。我有一个小书签来获取当前的 URL,或者我应该说主机名(没有 http://
部分 - 没关系),例如:
javascript:q=(document.location.host); void(open('http://mysite.com/search.php?search='+location.host,'_self','resizable,location,menubar,toolbar,scrollbars,status'));
问题是这个小书签只获取主机名,如 google .com,而不是像 google.com/sub/page.htm 这样的完整地址。有什么办法可以让我留下 http://
部分并获取剩余的网址吗?
The other day you were very helpful. Now I have another question. I have a bookmarklet to grab the current URL or I should say host name (without the http://
part - which is ok) like:
javascript:q=(document.location.host); void(open('http://mysite.com/search.php?search='+location.host,'_self','resizable,location,menubar,toolbar,scrollbars,status'));
The problem is that this bookmarklet only grabs the host name like google.com and not the whole address like google.com/sub/page.htm. Is there any way I can left the http://
part out and grab the remaining url?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您假设它是http(而不是https),那么以下内容应该可以工作:
当然,您需要在下面编写
q
而不是location.host
。如果您想做得更稳健,请使用 Location 对象的属性 并连接你想要的。
If you assume that it's http (not https), then the following should work:
Of course, you need to write
q
instead oflocation.host
in what follows.If you want to do it more robustly, use the properties of the Location object and concatenate the ones you want.