a53b9958fa734f73aeffb9ddfe2fbad1ca65f90c
galt
  Mon Jan 30 16:18:41 2017 -0800
Check-in of CSP2 Content-Security-Policy work. All C-language CGIs should now support CSP2 in browser to stop major forms of XSS javascript injection. Javascript on pages is gathered together, and then emitted in a single script block at the end with a nonce that tells the browser, this is js that we generated instead of being injected by a hacker. Both inline script from script blocks and inline js event handlers had to be pulled out and separated. You will not see js sprinkled through-out the page now. Older browsers that support CSP1 or that do not understand CSP at all will still work, just without protection. External js libraries loaded at runtime need to be added to the CSP policy header in src/lib/htmshell.c.

diff --git src/hg/hgTracks/hgTracks.c src/hg/hgTracks/hgTracks.c
index 76eef91..8162e6c 100644
--- src/hg/hgTracks/hgTracks.c
+++ src/hg/hgTracks/hgTracks.c
@@ -714,31 +714,34 @@
     // but in virtMode we may be in a window that is smaller than the ideo width
     // so temporarily set them to the actual ideo graphic offset and width
     int saveInsideX = insideX;
     int saveInsideWidth = insideWidth;
     insideX = textWidth+4;
     insideWidth = ideoWidth-insideX;
     ideoTrack->drawItems(ideoTrack, winStart, winEnd, hvg, insideX, gfxBorder,
                          insideWidth, font, ideoTrack->ixColor, ideoTrack->limitedVis);
     insideX = saveInsideX;
     insideWidth = saveInsideWidth;
     hvGfxUnclip(hvg);
     /* Save out picture and tell html file about it. */
     hvGfxClose(&hvg);
     /* Finish map. */
     if (!psOutput)
+	{
         hPrintf("</MAP>\n");
+	jsInline("$('area.cytoBand').click(function(){return false;});\n");
+	}
     }
 
 // create an empty hidden-map place holder which can change dynamically with ajax callbacks.
 if (!doIdeo && !psOutput) 
     {
     hPrintf("<MAP Name=%s>\n", mapName);
     hPrintf("</MAP>\n");
     }
 
 hPrintf("<TABLE BORDER=0 CELLPADDING=0>");
 if (!psOutput)
     {
     // by default, create an empty hidden ideo place holder for future dynamic ajax update
     char *srcPath = "";
     char *style = "display: none;";
@@ -6459,30 +6462,31 @@
     /* or maybe errabort ? */
     label[3] = 0;
     len = 4;
     }
 if (len % 2 != 0)
     paddedLabel[3] = 0;
 if (len == strlen(paddedLabel))
     strcpy(paddedLabel, label);
 else
     {
     int i;
     for (i=0; i<len; i++)
         paddedLabel[i+1] = label[i];
     }
 hButtonWithOnClick(var, paddedLabel, NULL, "return imageV2.navigateButtonClick(this);");
+// TODO GALT could consider trying to give these all the same class and then attach handlers at the class level.
 }
 
 void limitSuperTrackVis(struct track *track)
 /* Limit track visibility by supertrack parent */
 {
 if (tdbIsSuperTrackChild(track->tdb))
     {
     assert(track->tdb->parent != NULL);
     if (sameString("hide", cartUsualString(cart, track->tdb->parent->track,
                                            track->tdb->parent->isShow ? "show" : "hide")))
         track->visibility = tvHide;
     }
 }
 
 struct track *rFindTrackWithTable(char *tableName, struct track *trackList)
@@ -7213,30 +7217,32 @@
 	sharedErrMsg = tg->networkErrMsg;
 	break;
 	}
     }
 if (sharedErrMsg)
     {
     for (tg=track; tg; tg=tg->nextWindow)
 	{
 	tg->networkErrMsg = sharedErrMsg;
 	tg->drawItems = bigDrawWarning;
 	tg->totalHeight = bigWarnTotalHeight;
 	}
     }
 }
 
+
+
 void doTrackForm(char *psOutput, struct tempName *ideoTn)
 /* Make the tracks display form with the zoom/scroll buttons and the active
  * image.  If the ideoTn parameter is not NULL, it is filled in if the
  * ideogram is created.  */
 {
 struct group *group;
 struct track *track;
 char *freezeName = NULL;
 boolean hideAll = cgiVarExists("hgt.hideAll");
 boolean defaultTracks = cgiVarExists("hgt.reset");
 boolean showedRuler = FALSE;
 boolean showTrackControls = cartUsualBoolean(cart, "trackControlsOnMain", TRUE);
 long thisTime = 0, lastTime = 0;
 
 basesPerPixel = ((float)virtWinBaseCount) / ((float)fullInsideWidth);
@@ -7794,35 +7800,35 @@
         hPrintf("<FORM ACTION=\"%s\" NAME=\"TrackForm\" id=\"TrackForm\" METHOD=\"POST\">\n\n",
                 hgTracksName());
 	    hPrintf("%s", trackGroupsHidden2->string);
 	    freeDyString(&trackGroupsHidden1);
 	    freeDyString(&trackGroupsHidden2);
 	if (!psOutput) cartSaveSession(cart);   /* Put up hgsid= as hidden variable. */
 	hPrintf("<CENTER>");
 	}
 
 
     /* Make line that says position. */
 	{
 	char buf[256];
 	char *survey = cfgOptionEnv("HGDB_SURVEY", "survey");
 	char *surveyLabel = cfgOptionEnv("HGDB_SURVEY_LABEL", "surveyLabel");
-	    char *javascript = "onchange=\"document.location = '/cgi-bin/hgTracks?db=' + document.TrackForm.db.options[document.TrackForm.db.selectedIndex].value;\"";
+	    char *javascript = "document.location = '/cgi-bin/hgTracks?db=' + document.TrackForm.db.options[document.TrackForm.db.selectedIndex].value;";
 	    if (containsStringNoCase(database, "zoo"))
 		{
 		hPuts("Organism ");
-		printAssemblyListHtmlExtra(database, javascript);
+		printAssemblyListHtmlExtra(database, "change", javascript);
 		}
 
 	if (virtualSingleChrom()) // DISGUISE VMODE
 	    safef(buf, sizeof buf, "%s", windowsSpanPosition());
 	else
 	    safef(buf, sizeof buf, "%s:%ld-%ld", virtChromName, virtWinStart+1, virtWinEnd);
 	
 	position = cloneString(buf);
 	hPrintf("<span class='positionDisplay' id='positionDisplay' title='click to copy position to input box'>%s</span>", addCommasToPos(database, position));
 	hPrintf("<input type='hidden' name='position' id='position' value='%s'>\n", buf);
 	sprintLongWithCommas(buf, virtWinEnd - virtWinStart);
 	hPrintf(" <span id='size'>%s</span> bp. ", buf);
 	hPrintf("<input class='positionInput' type='text' name='hgt.positionInput' id='positionInput' size='60'>\n");
 	hWrites(" ");
 	hButton("hgt.jump", "go");
@@ -7970,40 +7976,41 @@
         {
         cgiMakeButtonWithMsg(TRACK_SEARCH, TRACK_SEARCH_BUTTON,TRACK_SEARCH_HINT);
         hPrintf(" ");
         }
     hButtonWithMsg("hgt.reset", "default tracks","Display only default tracks");
     hPrintf("&nbsp;");
     hButtonWithMsg("hgt.defaultImgOrder", "default order",
                    "Display current tracks in their default order");
     // if (showTrackControls)  - always show "hide all", Hiram 2008-06-26
         {
         hPrintf("&nbsp;");
         hButtonWithMsg("hgt.hideAll", "hide all","Hide all currently visibile tracks");
         }
 
     hPrintf(" ");
-    hPrintf("<INPUT TYPE='button' VALUE='%s' onClick='document.customTrackForm.submit();"
-            "return false;' title='%s'>",
+    hPrintf("<INPUT TYPE='button' id='ct_add' VALUE='%s' title='%s'>",
             hasCustomTracks ? CT_MANAGE_BUTTON_LABEL : CT_ADD_BUTTON_LABEL,
             hasCustomTracks ? "Manage your custom tracks" : "Add your own custom tracks");
+    jsOnEventById("click", "ct_add", "document.customTrackForm.submit();return false;");
 
     hPrintf(" ");
     if (hubConnectTableExists())
         {
-        hPrintf("<INPUT TYPE='button' VALUE='track hubs' onClick='document.trackHubForm.submit();"
+        hPrintf("<INPUT TYPE='button' id='th_form' VALUE='track hubs'"
                 "return false;' title='Import tracks from hubs'>");
+	jsOnEventById("click", "th_form", "document.trackHubForm.submit();");
         hPrintf(" ");
         }
 
     hButtonWithMsg("hgTracksConfigPage", "configure","Configure image and track selection");
     hPrintf(" ");
 
     hButtonWithOnClick("hgTracksConfigMultiRegionPage", 
 	"multi-region", "Configure multi-region display options", "popUpHgt.hgTracks('multi-region config'); return false;");
     hPrintf(" ");
 
     if (!hIsGsidServer())
         {
         hButtonWithMsg("hgt.toggleRevCmplDisp", "reverse",
                        revCmplDisp ? "Show forward strand at this location"
                                    : "Show reverse strand at this location");
@@ -8067,41 +8074,53 @@
 	    char *indicator;
 	    char *indicatorImg;
 	    boolean isOpen = !isCollapsedGroup(group);
 	    collapseGroupGoodies(isOpen, TRUE, &indicatorImg,
 				    &indicator, &otherState);
 	    hPrintf("<TR>");
 	    cg->rowOpen = TRUE;
             if (!hIsGsidServer())
                 hPrintf("<th align=\"left\" colspan=%d class='blueToggleBar'>",MAX_CONTROL_COLUMNS);
             else
                 hPrintf("<th align=\"left\" colspan=%d class='blueToggleBar'>",
                         MAX_CONTROL_COLUMNS-1);
 
             hPrintf("<table style='width:100%%;'><tr><td style='text-align:left;'>");
             hPrintf("\n<A NAME=\"%sGroup\"></A>",group->name);
-            hPrintf("<IMG class='toggleButton' onclick=\"return vis.toggleForGroup(this, '%s');\" "
+
+            hPrintf("<IMG class='toggleButton'"
                     " id=\"%s_button\" src=\"%s\" alt=\"%s\" title='%s this group'>&nbsp;&nbsp;",
-                    group->name, group->name, indicatorImg, indicator,isOpen?"Collapse":"Expand");
+                    group->name, indicatorImg, indicator,isOpen?"Collapse":"Expand");
+	    char jsText[256];
+	    safef(jsText, sizeof jsText, "return vis.toggleForGroup(this, '%s');", group->name);
+	    char idText[256];
+	    safef(idText, sizeof idText, "%s_button", group->name);
+	    jsOnEventById("click", idText, jsText);
+
             hPrintf("</td><td style='text-align:center; width:90%%;'>\n<B>%s</B>", group->label);
             hPrintf("</td><td style='text-align:right;'>\n");
             if (isHubTrack(group->name))
-                hPrintf("<input name=\"hubDisconnectButton\""
-                    "onClick="
-                    "\" document.disconnectHubForm.elements['hubId'].value= '%s';"
-                    "document.disconnectHubForm.submit();return true;\" "
-                    "type=\"button\" value=\"disconnect\">\n", &group->name[sizeof hubTrackPrefix - 1]);
+		{
+                hPrintf("<input name=\"hubDisconnectButton\" id='hub_disconn'"
+                    "type=\"button\" value=\"disconnect\">\n");
+		safef(jsText, sizeof jsText, 
+                    "document.disconnectHubForm.elements['hubId'].value='%s';"
+                    "document.disconnectHubForm.submit();return true;",
+		    &group->name[sizeof hubTrackPrefix - 1]);
+		jsOnEventById("click", "hub_disconn", jsText);
+		}
+
             hPrintf("<input type='submit' name='hgt.refresh' value='refresh' "
                     "title='Update image with your changes'>\n");
             hPrintf("</td></tr></table></th>\n");
             controlGridEndRow(cg);
 
             /* Base Position track goes into map group, which will always exist. */
             if (!showedRuler && sameString(group->name, "map") )
 		{
 		char *url = trackUrl(RULER_TRACK_NAME, chromName);
 		showedRuler = TRUE;
 		myControlGridStartCell(cg, isOpen, group->name);
 		hPrintf("<A HREF=\"%s\">", url);
 		hPrintf(" %s<BR> ", RULER_TRACK_LABEL);
 		hPrintf("</A>");
 		hDropListClassWithStyle("ruler", rulerMenu,
@@ -8710,33 +8729,35 @@
 
 // ajax callback to convert chrom position to virt chrom position
 if (cartVarExists(cart, "hgt.convertChromToVirtChrom")) 
     {
     position = cartString(cart, "hgt.convertChromToVirtChrom");
     char nvh[256];
     safef(nvh, sizeof nvh, "%s.%s", database, position);
     cartSetString(cart, "nonVirtHighlight", nvh);
     parseNonVirtPosition(position);
     if (findNearestVirtMatch(chromName, winStart, winEnd, FALSE, &virtWinStart, &virtWinEnd))
 	{
 	struct jsonElement *jsonForConvert = NULL;
 	jsonForConvert = newJsonObject(newHash(8));
 	jsonObjectAdd(jsonForConvert, "virtWinStart", newJsonNumber(virtWinStart));
 	jsonObjectAdd(jsonForConvert, "virtWinEnd", newJsonNumber(virtWinEnd));
-	hPrintf("<script type='text/javascript'>\n");
-	jsonPrint((struct jsonElement *) jsonForConvert, "convertChromToVirtChrom", 0);
-	hPrintf("</script>\n");
+
+	struct dyString *dy = dyStringNew(1024);
+	jsonDyStringPrint(dy, (struct jsonElement *) jsonForConvert, "convertChromToVirtChrom", 0);
+	jsInline(dy->string);
+	dyStringFree(&dy);
 	}
     return;
     }
 
 lastVirtModeExtraState = cartUsualString(cart, "lastVirtModeExtraState", lastVirtModeExtraState); 
 
 // DISGUISED POSITION
 if (!startsWith("virt:", position) && (virtualSingleChrom()))
     {
     // "virtualSingleChrom trying to find best vchrom location corresponding to chromName, winStart, winEnd
     findNearest = TRUE;
 
      // try to find the nearest match
     if (!(chromName && findNearestVirtMatch(chromName, winStart, winEnd, findNearest, &virtWinStart, &virtWinEnd)))
 	{ // create 1k window near middle of vchrom
@@ -9386,99 +9407,105 @@
 /* Reset vars except for position and database. */
 {
 static char *except[] = {"db", "position", NULL};
 char *cookieName = hUserCookie();
 char *sessionId = cgiOptionalString(cartSessionVarName());
 char *userId = findCookieData(cookieName);
 struct cart *oldCart = cartNew(userId, sessionId, NULL, NULL);
 cartRemoveExcept(oldCart, except);
 cartCheckout(&oldCart);
 cgiVarExcludeExcept(except);
 }
 
 void setupHotkeys(boolean gotExtTools)
 /* setup keyboard shortcuts and a help dialog for it */
 {
+struct dyString *dy = dyStringNew(1024);
 // wire the keyboard hotkeys
-hPrintf("<script type='text/javascript'>\n");
+
 // left
-hPrintf("Mousetrap.bind('ctrl+j', function() { $('input[name=\"hgt.left1\"]').click(); return false; }); \n");
-hPrintf("Mousetrap.bind('j', function() { $('input[name=\"hgt.left2\"]').click() }); \n");
-hPrintf("Mousetrap.bind('J', function() { $('input[name=\"hgt.left3\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('ctrl+j', function() { $('input[name=\"hgt.left1\"]').click(); return false; }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('j', function() { $('input[name=\"hgt.left2\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('J', function() { $('input[name=\"hgt.left3\"]').click() }); \n");
 
 // right
-hPrintf("Mousetrap.bind('ctrl+l', function() { $('input[name=\"hgt.right1\"]').click(); return false; }); \n");
-hPrintf("Mousetrap.bind('l', function() { $('input[name=\"hgt.right2\"]').click() }); \n");
-hPrintf("Mousetrap.bind('L', function() { $('input[name=\"hgt.right3\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('ctrl+l', function() { $('input[name=\"hgt.right1\"]').click(); return false; }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('l', function() { $('input[name=\"hgt.right2\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('L', function() { $('input[name=\"hgt.right3\"]').click() }); \n");
 
 // zoom in
-hPrintf("Mousetrap.bind('ctrl+i', function() { $('input[name=\"hgt.in1\"]').click(); return false; }); \n");
-hPrintf("Mousetrap.bind('i', function() { $('input[name=\"hgt.in2\"]').click() }); \n");
-hPrintf("Mousetrap.bind('I', function() { $('input[name=\"hgt.in3\"]').click() }); \n");
-hPrintf("Mousetrap.bind('b', function() { $('input[name=\"hgt.inBase\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('ctrl+i', function() { $('input[name=\"hgt.in1\"]').click(); return false; }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('i', function() { $('input[name=\"hgt.in2\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('I', function() { $('input[name=\"hgt.in3\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('b', function() { $('input[name=\"hgt.inBase\"]').click() }); \n");
 
 // zoom out
-hPrintf("Mousetrap.bind('ctrl+k', function() { $('input[name=\"hgt.out1\"]').click(); return false; }); \n");
-hPrintf("Mousetrap.bind('k', function() { $('input[name=\"hgt.out2\"]').click() }); \n");
-hPrintf("Mousetrap.bind('K', function() { $('input[name=\"hgt.out3\"]').click() }); \n");
-hPrintf("Mousetrap.bind('0', function() { $('input[name=\"hgt.out4\"]').click() }); \n");
-hPrintf("Mousetrap.bind('1', function() { zoomTo(50);} ); \n");
-hPrintf("Mousetrap.bind('2', function() { zoomTo(500);} ); \n");
-hPrintf("Mousetrap.bind('3', function() { zoomTo(5000);} ); \n");
-hPrintf("Mousetrap.bind('4', function() { zoomTo(50000);} ); \n");
-hPrintf("Mousetrap.bind('5', function() { zoomTo(500000);} ); \n");
-hPrintf("Mousetrap.bind('6', function() { zoomTo(5000000);} ); \n");
+dyStringPrintf(dy,"Mousetrap.bind('ctrl+k', function() { $('input[name=\"hgt.out1\"]').click(); return false; }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('k', function() { $('input[name=\"hgt.out2\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('K', function() { $('input[name=\"hgt.out3\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('0', function() { $('input[name=\"hgt.out4\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('ctrl+k', function() { $('input[name=\"hgt.out1\"]').click(); return false; }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('k', function() { $('input[name=\"hgt.out2\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('K', function() { $('input[name=\"hgt.out3\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('0', function() { $('input[name=\"hgt.out4\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('1', function() { zoomTo(50);} ); \n");
+dyStringPrintf(dy,"Mousetrap.bind('2', function() { zoomTo(500);} ); \n");
+dyStringPrintf(dy,"Mousetrap.bind('3', function() { zoomTo(5000);} ); \n");
+dyStringPrintf(dy,"Mousetrap.bind('4', function() { zoomTo(50000);} ); \n");
+dyStringPrintf(dy,"Mousetrap.bind('5', function() { zoomTo(500000);} ); \n");
+dyStringPrintf(dy,"Mousetrap.bind('6', function() { zoomTo(5000000);} ); \n");
 
 // buttons
-hPrintf("Mousetrap.bind('c f', function() { $('input[name=\"hgTracksConfigPage\"]').click() }); \n");
-hPrintf("Mousetrap.bind('t s', function() { $('input[name=\"hgt_tSearch\"]').click() }); \n");
-hPrintf("Mousetrap.bind('h a', function() { $('input[name=\"hgt.hideAll\"]').click() }); \n");
-hPrintf("Mousetrap.bind('d t', function() { $('input[name=\"hgt.reset\"]').click() }); \n");
-hPrintf("Mousetrap.bind('d o', function() { $('input[name=\"hgt.defaultImgOrder\"]').click() }); \n");
-hPrintf("Mousetrap.bind('c t', function() { document.customTrackForm.submit();return false; }); \n");
-hPrintf("Mousetrap.bind('t h', function() { document.trackHubForm.submit();return false; }); \n");
-hPrintf("Mousetrap.bind('r s', function() { $('input[name=\"hgt.setWidth\"]').click() }); \n");
-hPrintf("Mousetrap.bind('r f', function() { $('input[name=\"hgt.refresh\"]').click() }); \n");
-hPrintf("Mousetrap.bind('r v', function() { $('input[name=\"hgt.toggleRevCmplDisp\"]').click() }); \n");
-hPrintf("Mousetrap.bind('v d', gotoGetDnaPage); \n");
+dyStringPrintf(dy,"Mousetrap.bind('c f', function() { $('input[name=\"hgTracksConfigPage\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('t s', function() { $('input[name=\"hgt_tSearch\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('h a', function() { $('input[name=\"hgt.hideAll\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('d t', function() { $('input[name=\"hgt.reset\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('d o', function() { $('input[name=\"hgt.defaultImgOrder\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('c t', function() { document.customTrackForm.submit();return false; }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('t h', function() { document.trackHubForm.submit();return false; }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('r s', function() { $('input[name=\"hgt.setWidth\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('r f', function() { $('input[name=\"hgt.refresh\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('r v', function() { $('input[name=\"hgt.toggleRevCmplDisp\"]').click() }); \n");
+dyStringPrintf(dy,"Mousetrap.bind('v d', gotoGetDnaPage); \n");
 
 // focus
-hPrintf("Mousetrap.bind('/', function() { $('input[name=\"hgt.positionInput\"]').focus(); return false; }, 'keydown'); \n");
-hPrintf("Mousetrap.bind('?', showHotkeyHelp);\n");
+dyStringPrintf(dy,"Mousetrap.bind('/', function() { $('input[name=\"hgt.positionInput\"]').focus(); return false; }, 'keydown'); \n");
+dyStringPrintf(dy,"Mousetrap.bind('?', showHotkeyHelp);\n");
 
 // menu
 if (gotExtTools)
-    hPrintf("Mousetrap.bind('s t', showExtToolDialog); \n");
+    dyStringPrintf(dy,"Mousetrap.bind('s t', showExtToolDialog); \n");
 
 // multi-region views
-hPrintf("Mousetrap.bind('e v', function() { window.location.href='%s?%s=%s&virtModeType=exonMostly'; });  \n",
+dyStringPrintf(dy,"Mousetrap.bind('e v', function() { window.location.href='%s?%s=%s&virtModeType=exonMostly'; });  \n",
            hgTracksName(), cartSessionVarName(), cartSessionId(cart));
-hPrintf("Mousetrap.bind('d v', function() { window.location.href='%s?%s=%s&virtModeType=default'; });  \n",
+dyStringPrintf(dy,"Mousetrap.bind('d v', function() { window.location.href='%s?%s=%s&virtModeType=default'; });  \n",
            hgTracksName(), cartSessionVarName(), cartSessionId(cart));
 
 // links to a few tools
-hPrintf("Mousetrap.bind('t b', function() { $('#blatMenuLink')[0].click()});\n");
-hPrintf("Mousetrap.bind('t i', function() { $('#ispMenuLink')[0].click()});\n");
-hPrintf("Mousetrap.bind('t t', function() { $('#tableBrowserMenuLink')[0].click()});\n");
-hPrintf("Mousetrap.bind('c r', function() { $('#cartResetMenuLink')[0].click()});\n");
-hPrintf("Mousetrap.bind('s s', function() { $('#sessionsMenuLink')[0].click()});\n");
-hPrintf("Mousetrap.bind('p s', function() { $('#publicSessionsMenuLink')[0].click()});\n");
+dyStringPrintf(dy,"Mousetrap.bind('t b', function() { $('#blatMenuLink')[0].click()});\n");
+dyStringPrintf(dy,"Mousetrap.bind('t i', function() { $('#ispMenuLink')[0].click()});\n");
+dyStringPrintf(dy,"Mousetrap.bind('t t', function() { $('#tableBrowserMenuLink')[0].click()});\n");
+dyStringPrintf(dy,"Mousetrap.bind('c r', function() { $('#cartResetMenuLink')[0].click()});\n");
+dyStringPrintf(dy,"Mousetrap.bind('s s', function() { $('#sessionsMenuLink')[0].click()});\n");
+dyStringPrintf(dy,"Mousetrap.bind('p s', function() { $('#publicSessionsMenuLink')[0].click()});\n");
 
 // also add an entry to the help menu that shows the keyboard shortcut help dialog
-hPrintf("$(document).ready(addKeyboardHelpEntries);");
+dyStringPrintf(dy,"$(document).ready(addKeyboardHelpEntries);\n");
 
-hPrintf("</script>\n");
+jsInline(dy->string);
+dyStringFree(&dy);
 
 // help dialog
 hPrintf("<div style=\"display:none\" id=\"hotkeyHelp\" title=\"Keyboard shortcuts\">\n");
 hPrintf("<table style=\"width:580px; border-color:#666666; border-collapse:collapse\">\n");
 hPrintf("<tr><td style=\"width:18ch\">left 10&#37;</td><td width=\"auto\" class=\"hotkey\">ctrl+j</td>  <td style=\"width:24ch\"> track search</td><td class=\"hotkey\">t then s</td>               </tr>\n"); // percent sign
 hPrintf("<tr><td> left 1/2 screen</td><td class=\"hotkey\">j</td>   <td> default tracks</td><td class=\"hotkey\">d then t</td>             </tr>\n");
 hPrintf("<tr><td> left one screen</td><td class=\"hotkey\">J</td>   <td> default order</td><td class=\"hotkey\">d then o</td>              </tr>\n");
 hPrintf("<tr><td> right 10&#37;</td><td class=\"hotkey\">ctrl+l</td><td> hide all</td><td class=\"hotkey\">h then a</td>                   </tr>\n"); // percent sign
 hPrintf("<tr><td> right 1/2 screen</td><td class=\"hotkey\">l</td>  <td> custom tracks</td><td class=\"hotkey\">c then t</td>              </tr>\n");
 hPrintf("<tr><td> right one screen</td><td class=\"hotkey\">L</td>  <td> track hubs</td><td class=\"hotkey\">t then h</td>                 </tr>\n");
 hPrintf("<tr><td> zoom in 1.5x</td><td class=\"hotkey\">ctrl+i</td> <td> configure</td><td class=\"hotkey\">c then f</td>                  </tr>\n"); 
 hPrintf("<tr><td> zoom in 3x</td><td class=\"hotkey\">i</td>        <td> reverse</td><td class=\"hotkey\">r then v</td>                    </tr>\n");
 hPrintf("<tr><td> zoom in 10x</td><td class=\"hotkey\">I</td>       <td> resize</td><td class=\"hotkey\">r then s</td>                     </tr>\n");
 hPrintf("<tr><td> zoom in base level</td><td class=\"hotkey\">b</td><td> refresh</td><td class=\"hotkey\">r then f</td>                    </tr>\n");
 hPrintf("<tr><td> zoom out 1.5x</td><td class=\"hotkey\">ctrl+k</td><td> jump to position box</td><td class=\"hotkey\">/</td>              </tr>\n"); 
@@ -9686,37 +9713,38 @@
     }
 
 if (cartVarExists(cart, "hgt.convertChromToVirtChrom"))
     {
     cartRemove(cart, "hgt.convertChromToVirtChrom");
     return;
     }
 
 jsonObjectAdd(jsonForClient, "measureTiming", newJsonBoolean(measureTiming));
 // js code needs to know if a highlightRegion is defined for this db
 char *highlightDef = cartOptionalString(cart, "highlight");
 if (highlightDef && startsWith(database,highlightDef) && highlightDef[strlen(database)] == '.')
     jsonObjectAdd(jsonForClient, "highlight", newJsonString(highlightDef));
 jsonObjectAdd(jsonForClient, "enableHighlightingDialog",
 	      newJsonBoolean(cartUsualBoolean(cart, "enableHighlightingDialog", TRUE)));
-hPrintf("<script type='text/javascript'>\n");
-jsonPrint((struct jsonElement *) jsonForClient, "hgTracks", 0);
-hPrintf("</script>\n");
+
+struct dyString *dy = dyStringNew(1024);
+jsonDyStringPrint(dy, (struct jsonElement *) jsonForClient, "hgTracks", 0);
+jsInline(dy->string);
+dyStringFree(&dy);
 
 boolean gotExtTools = extToolsEnabled();
 setupHotkeys(gotExtTools);
 if (gotExtTools)
     printExtMenuData();
 
 if (measureTiming)
     measureTime("Time at end of doMiddle, next up cart write");
 
 if (cartOptionalString(cart, "udcTimeout"))
     {
     warn("The Genome Browser cart currently includes the \"udcTimeout\" string. "
 	"While this is useful for debugging hubs, it may negatively impact "
 	"performance.   To clear this variable, click "
 	"<A HREF='hgTracks?hgsid=%s|url|&udcTimeout=[]'>here</A>.",cartSessionId(cart));
     }
-
 }