0

The company I work for updated its DNS settings in our country and now a lots of old links without fully qualified domain name don't work anymore.

Before:
http://server:8080/something

After:
http://server.company.com:8080/something

But other countries and servers still use the old format (they will be migrated over the coming years) and we get a lot of old links in mail and chat and when we click those the browser can't open them.

I would like to write a bookmarklet that replaces the old URL to the new one, something like:

javascript:window.location.href=window.location.href.replace(/(^http:\/\/[^.]*):/,'$1.company.com:')

Unfortunately, the bookmarklet doesn't work because the page was not loaded and thus window.location.href does not contain the URL to be replaced.

Can I somehow still access the URL that was entered in the browser's location bar?

Or there is no way and I need to create a browser extension for that?

zengabor
  • 2,013
  • 3
  • 23
  • 28

2 Answers2

0

Option 1: Prompt user for input. They have to copy/paste the URL.

Option 2: Create a very simple web page that accepts the URL as query parameter, rewrites it, and redirects. Setup the search bar to use that page. Can then paste links into search bar without need to click a bookmarklet. Can even drag links into search bar. If you want search bar to still search, redirect any non-URL text to Google.

Option 3: Create a very simple web page that will redirect to correct URL. Update hosts to point "server" at that web page. If you can't update DNS, update hosts file.

DG.
  • 3,417
  • 2
  • 23
  • 28
  • I'm not sure I follow all of the above. This thing would be just a convenience solution for a few of us so that we can avoid typing `.company.com` many times a day. I am not sure if it's worth it if we have to do anything more than just clicking a button (like copying the URL, opening a site and then pasting it, etc.). Unfortunately we cannot change the DNS and our hosts files. :( – zengabor Jun 14 '13 at 14:49
0

I ended up creating a Chrome extension which works great: we just hit the button and the correct page is opened. Here are some relevant parts from this extension:

manifest.json

{
    "manifest_version": 2,
    "name": "Name of extension",
    "permissions": [
        "activeTab"
    ],
    "background": {
        "scripts": ["script.js"],
        "persistent": false
    },
    "browser_action": {
        "default_icon": "icon.png",
        "default_title": "Tooltip for button"
    }
}

script.js

chrome.browserAction.onClicked.addListener(function(tab) {
    var $before = tab.url,
        $after = $before.replace(/(^http:\/\/[^.:\/]*)([:\/])/,'$1.company.com$2');
    if ($before !== $after) {
        chrome.tabs.update(tab.id, {url: $after});
    }
});
zengabor
  • 2,013
  • 3
  • 23
  • 28