0

Hi i need to get current domain name or url with jquery in my MVC website.

Here is my code:

 <script>
 // var ROOT = 'http://192.168.1.100/';
  var ROOT = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
  $(document).ready(function () {
  $('.button-search').click(function () {
window.location =ROOT + "Products/Index?DepartmentId=" +  $.trim($('#filter_name').val());                               
    });
});

My website url liks like this way:

 http://192.168.1.100/Home/Index

          OR
www.abc.com/Home/Index

I want to fetch http://192.168.1.100/ or www.abc.com/ with the help of jquery in my above code.

Please suggest.

Tieson T.
  • 20,774
  • 6
  • 77
  • 92
user1638889
  • 41
  • 1
  • 10
  • 1
    Why do you think you need it? You can just use `window.location =' @Url.Action("Index", "Products") + '?DepartmentId=' + $.trim($('#filter_name').val());` –  Apr 21 '15 at 22:44
  • Here is the answer http://stackoverflow.com/questions/6941533/get-protocol-domain-and-port-from-url – pjobs Apr 21 '15 at 22:45
  • @StephenMuecke thanks i am trying this. – user1638889 Apr 21 '15 at 22:50

1 Answers1

0

to get the website current domain of the you tab use

window.location.host

and you can try this simple snippet code

alert("full link :\n"+window.location+"\n website domain :\n"+window.location.host)
Anis Boukhris
  • 421
  • 2
  • 6