Replace end characters of current URL with bookmar

2019-07-13 18:43发布

Is there a way to replace all characters after the last backslash in the currentURL with another string via javascript bookmarklet?

I'm doing a lot of auditing work with Sharepoint sites and having to manually look at the settings pages for sites by entering strings to the end of a URL. For example, I might go to a site like:

https://site.com/..../default.aspx

And I replace the "default.aspx" with "_layouts/user.aspx" and reload the new page so it is now at:

https://site.com/..../_layouts/user.aspx

It's not always "default.aspx", so I can't just use a simple string replace. I know there is a way to manipulate the URL via a javascript bookmarklet, but my knowledge of how to do that is limited at best. Any help or guidance would be greatly appreciated

1条回答
时光不老,我们不散
2楼-- · 2019-07-13 19:18

I don't know if this is what you thought, but if you just want to change the last part of the url with something else, you could use this bookmarklet

javascript:(function(){ 

var curloc = document.location.href.split('/');
var urlEnding= '/_layouts/user.aspx';
curloc = curloc.splice(0,curloc.length-1).join('/')+urlEnding;
document.location.href = curloc;

})();

You could replace the fixed url with

prompt('Enter your url:', '_layouts/user.aspx');

if you need to change the last part each time.

I hope this helps.

查看更多
登录 后发表回答