Updated the javascript to handle external URLs