我遇到了奇怪的情况。我正在编写一个JavaScript书签,使用户可以轻松快速地点击并分享外部网站到我们的网站上。它只是获取标题、页面URL以及如果他们在页面上选择任何文本,也会抓取它。
问题是它在外部域名上不起作用,因此如果我们在内部使用它,就会得到这样格式化的URL:
http://internaldomain.com/sharetool.php?shareid=http://internaldomain.com/anotheroddpage.html&title=....
这很好,但是如果我们尝试使用外部域名,并且得到这样格式化的URL:
那么我们的页面会出现Forbidden Error错误,无法加载... 如果我们手动从外部域名地址中删除http://
,它就可以正常加载。
因此... 我认为解决此问题的最佳方法是修改JavaScript书签,在加载窗口时移除http
。这是我的当前书签的样子:
javascript:var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='http://internaldomain.com/sharetool.php',l=d.location,e=encodeURIComponent,u=f+'?u='+e(l.href)+
从中你可以看到,e(l.href)
是 URL 被传递的地方。
我该如何修改它以删除外部域名中的 http://
?
/^\/\/|^.*?:\/\//
(您可以改进它,我相信)。 - Dan.replace(/^\/\/|^.*?:(\/\/)?/, '');
- gdibble(^\w+:|^)
? - Rahul