E
E
Eugene2011-01-29 17:45:25
JavaScript
Eugene, 2011-01-29 17:45:25

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

3 answer(s)
V
voicer, 2011-01-31
@CB9TOIIIA

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);

B
Blangel, 2011-01-30
@Blangel

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);
});
};

S
sajgak, 2011-01-29
@sajgak

www.w3schools.com/jsref/jsref_match.asp i think this will help you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question