Answer the question
In order to leave comments, you need to log in
Javascript: path from root url
Greetings. I am creating an extension for chrome. And I encountered difficulty in writing the path from the root of the site (domain): as a basis, I look at the extension - link
Ie . from under the main page everything works correctly, tk. go to /robots.txt. But if the user left the main page, then, of course, this is not what is needed.
It is clear that he " tab.url " takes a tab - but here's how to remove everything from it before "/"?
How to correctly write in the line:
So that he takes from the root?
WebDeveloper.Popup.Tools = {};
$(function()
{
$("#joomla-robots").click(WebDeveloper.Popup.Tools.robots);
});
WebDeveloper.Popup.Tools.robots = function()
{
var featureItem = $(this);
WebDeveloper.Popup.getSelectedTab(function(tab)
{
WebDeveloper.Popup.openTab(tab.url + "robots.txt", featureItem);
});
};
WebDeveloper.Popup.openTab(tab.url + "robots.txt", featureItem);
Answer the question
In order to leave comments, you need to log in
N-yes, comrades answering.
In fact, there is a special window.location object specifically for such cases, which contains already parsed information about the current URL.
developer.mozilla.org/en/DOM/window.location
In your case,
WebDeveloper.Popup.openTab(location.origin + '/robots.txt', featureItem);
It's not entirely clear why delete before the slash?
tab.url is the address of the current page... what do we need? get robots.txt from the root of the current site?.. So simple...
WebDeveloper.Popup.getSelectedTab(function(tab)
{
var parts = tab.url.split(new RegExp("/", "g"));
WebDeveloper. Popup.openTab(parts[0] + "//" + parts[1] + "/robots.txt", featureItem);
});
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question