Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current URL with JavaScript? [duplicate]

Tags:

javascript

url

I have this portion of the code. I want to know how can I read the url as the current page instead a fix url

Here is the portion of the coding:

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;

You see currently it has a fix reading the url http://store.ijdmtoy.com/SearchResults.asp

For example, I am currently on http://store.ijdmtoy.com/abs.htm

How can I change the code so it will automatically read as http://store.ijdmtoy.com/abs.htm?searching=Y&Search

like image 879
user3440511 Avatar asked Dec 28 '25 16:12

user3440511


1 Answers

If you are currently on http://store.ijdmtoy.com/abs.htm then document.URL will be http://store.ijdmtoy.com/abs.htm.

You can try:

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

like image 165
tchow002 Avatar answered Dec 31 '25 08:12

tchow002



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!