Javascript: the path from the root url


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
35 views
Welcome. Create an extension called chrome. And faced with the difficulty to set the path from the site root (domain): based on looking extension — link

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


I.e., under the main page all works correctly, because the transition /robots.txt. But if the user left the main page, then there is of course not what we need.

It is clear that it "tab.url" picks up the tab — but that's how all of it before the "/" to remove?

How to register in line:
WebDeveloper.Popup.openTab(tab.url + "robots.txt", featureItem);

To root took?
by | 35 views

3 Answers

0 like 0 dislike
Oh, Yes, comrades in charge.
\r
Actually, specially for such cases there is a special window object.location that contains already rasparennouu information about the current URL ie
\rdeveloper.mozilla.org/en/DOM/window.location
\r
In your case will fit:
WebDeveloper.Popup.openTab(location.origin + '/robots.txt', featureItem);
by
0 like 0 dislike
It is not clear why to remove it before slash?
tab.url is the address of the current page... and us? take robots.txt from the root of the current site?.. So simple...
\r
WebDeveloper.Popup.getSelectedTab(function(tab)
{
var parts = tab.url.split(new RegExp("/", "g"));
WebDeveloper.Popup.openTab(parts[0] + "//" + parts[1] + "/robots.txt", featureItem);
});
};
by
0 like 0 dislike
by
110,608 questions
257,186 answers
0 comments
28,070 users