How can you dynamically switch SignalR hubs

I have 2 hubs that live on 2 different servers. Ideally I would like my series of webpages to connect to attempt to connect to 1 of these hubs, then if it fails switch to the other hub. Is this possible at all.

I can’t use the traditional method to connecting to the hub like so:

<script id="hubScript" src="IP:port/signalr/hubs"></script>
    $.connection.hub.url = SIGNALR_HUB_SERVER_1;
    srv = $.connection.tcpHub;

since I don’t know which hub I will be connecting to, or which hub will be alive.

Example of code that I have tried for reference

   if (document.head.getElementsByTagName("script").item(i).src == SIGNALR_HUB_SERVER_1 + "/hubs") {
        $.connection.hub.url = SIGNALR_HUB_SERVER_1;
   }
   else if(document.head.getElementsByTagName("script").item(i).src == SIGNALR_HUB_SERVER_2 + "/hubs") {
        $.connection.hub.url = SIGNALR_HUB_SERVER_2;
   }

When I try and connect using this code I get the error: “Error loading hubs. Ensure your hubs reference is correct”. This is because my script tag that contains the url is not the same as the url that I am trying to connect to.