Take path from application root in javascript [duplicate]
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.
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')
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 getsub.domain.com:8080
orsub.domain.com:80
window.location.hostname
: you'll getsub.domain.com
window.location.protocol
: you'll gethttp:
window.location.port
: you'll get8080
or80
window.location.origin
: you'll gethttp://sub.domain.com
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
精彩评论