I’m having an issue coming up with the correct window.location.href value for my button. Just so you know this is something that is done dynamically across all pages. So what I would like for it to do is go to the addnew function that resides in the current module controller that they are currently in. For example say the user is in the titles module(folder) and in the titles controller I want it to go to titles(module)/titles(controller)/addnew(method) but this is just an example. It works for this example however say I go to a different page say titleStatuses controller inside of the titles module which woudld be titles(module)/titleStatuses(controller) if I clicked the same button it woudl go to the titles(module)/titles(controller)/addnew(method).
$('.addnew').append('<button>Add New</button>').css('float', 'right').css('margin', '5px 0 0 10px').css('padding-right', '10px');
$('.addnew button').css('width', '100px').click(function() {
window.location.href = 'addnew';
return false;
});
Try this:
The href value on links will add on to the existing URL, which is what it seems you’re trying to do. However, when setting the URL via Javascript, “addnew” is the same as “/addnew”, which is the same as “http://domain.com/addnew”.
Using the method above (which assumes a trailing slash at the end of the URL) attaches the addnew function to the rest of the current URL.