Replace end characters of current URL with bookmarklet

南楼画角 提交于 2019-12-11 01:44:20

问题


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:


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.



来源:https://stackoverflow.com/questions/5972457/replace-end-characters-of-current-url-with-bookmarklet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!