5
function detailed_link(cell_rowid) {
        var $tabs = $('#infrTab').tabs();
        $tabs.tabs('select', 1); // switch to third tab~
        objRowData = $('#' + pageGridId).getRowData(cell_rowid);
        //document.getElementById("Name").value = objRowData.amount;

        loadPage('Infringement/TaskDetail', 'taskDetails'); /* Path */
    }

I have write a javascript function loadPage(), that needs a path to some page as a parameter. I need to give this path from the application root. I dont want a relative path. Please let me know how can I do it.

Vaibhav Jain
  • 33,887
  • 46
  • 110
  • 163

3 Answers3

6

I have this piece of Javascript in my Site.master, just underneath the jquery import and above any reference to my own scripts.

 <script type="text/javascript">
        //Function that provides a relative URL for cases of virtual directories.
        jQuery.url = function (path) {
            return '<%: Url.Action("Index","Home") %>' + path;
        };
 </script>

This assumes that your '/' address is handled by your Index method in your Home controller (the standard).

You can then access it via:

$.url('Infringement/TaskDetail')
Alastair Pitts
  • 19,423
  • 9
  • 68
  • 97
1

suppose that you have a page with this address: http://sub.domain.com/page.htm. use the following in page code to achive those results:

  • window.location.host : you'll get sub.domain.com:8080 or sub.domain.com:80
  • window.location.hostname : you'll get sub.domain.com
  • window.location.protocol : you'll get http:
  • window.location.port : you'll get 8080 or 80
  • window.location.origin : you'll get http://sub.domain.com
Amin Saqi
  • 18,549
  • 7
  • 50
  • 70
1

I recommend to use relative path, because you never know where will be application root. If your application will be installed with another applications in IIS, then its root could be for example http://www.domain.com/iis/youapp/pages/one.aspx

berushka
  • 11
  • 3