如何用JavaScript替换部分URL? [英] how to replace part of the URL with JavaScript?
问题描述
我有 http://域名。 com / Pages / SearchResults.aspx?function = search& selectedserver = intranet& search_query = MyRecords ,需要用类似于 http://domain.com/Pages/SearchResults.aspx?function=loginsearch&user=admin& ;密码= admin& selectedserver = intranet& search_query = MyRecords - 所以
I have something like http://domain.com/Pages/SearchResults.aspx?function=search&selectedserver=intranet&search_query=MyRecords and need to replace it by JavaScript with something similar to http://domain.com/Pages/SearchResults.aspx?function=loginsearch&user=admin&password=admin&selectedserver=intranet&search_query=MyRecords — so
function=search
正在替换为
function=loginsearch&user=admin&password=admin
URL中的
。需要帮助我应该将JavaScript保存为浏览器工具栏上的按钮,以便点击并更换地址栏中的URL。
inside the URL. Need help with what JavaScript should I save as a button on a browser's tool bar to click and have the URL in the address bar replaced.
推荐答案
var url = window.location.toString();
window.location = url.replace(/function=search/, 'function=loginsearch&user=admin&password=admin');
这篇关于如何用JavaScript替换部分URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!