如何使用 JavaScript 获取当前 URL?

use*_*511 3 javascript url

我有这部分代码。我想知道如何将 url 读取为当前页面而不是修复 url

这是编码的部分:

var str='';
      if(model_id != 0 ) str = model_id+"+";
      if(year_id != 0 ) str +=year_id+"+"; 
      url='http://store.ijdmtoy.com/SearchResults.asp?Search='+str;
top.location.href=url;
Run Code Online (Sandbox Code Playgroud)

你看到目前它有一个修复读取 url http://store.ijdmtoy.com/SearchResults.asp

例如,我目前在http://store.ijdmtoy.com/abs.htm

如何更改代码,使其自动读取为http://store.ijdmtoy.com/abs.htm?searching=Y&Search

tch*_*002 5

如果您目前在http://store.ijdmtoy.com/abs.htm 上,那么document.URL将会是http://store.ijdmtoy.com/abs.htm

你可以试试:

url = location.protocol + '//' + location.host + location.pathname + '?Search=' + str;