Manipulating the content of a specific page requires that you be able to definitively identify that the page is what is loaded. As far as I am aware, the dashboard has a unique content ID that you can search for to determine if you are on the dashboard page.
| // On Window Load | window.onload = (function() { | if(document.contains(document.getElementById('dashboard'))) { | // Code for dashboard-only button goes here | } | })(); |
|
However, on the slim chance that this ID is used on an alternate page, you can test the URL. Since the dashboard URL is always just the (sub)domain, it is relatively easy to test for:
| // On Window Load | window.onload = (function() { | if(/https?:\/\/(.[^\/]+)\/?$/.test(window.location.href)) { | // Code for dashboard-only button goes here | } | })(); |
|
I was able to successfully identify the dashboard between Beta, Test, and Live servers in Internet Explorer 11, Chrome 50, and Firefox 46 without issue. A dozen different pages were accessed to verify that neither option produced a false positive. Having said that, I would recommend the second option, simply because I can't promise the first won't result in a false positive.
The complexity of the (sub)domain is irrelevant, so long as there is no path beyond the initial URL.