3131 }
3232 }
3333 else {
34- //This content page is not in the expected frameset which contains the TOC so
35- //reload the parent frame and cause it to reload this page in the frame. The
36- //canonical link element contains the link to reload the entire parent frameset
37- //and load this current content page.
38- var pageLink = jQuery ( "link[rel='canonical']" ) . attr ( 'href' ) ;
39- if ( pageLink !== '' ) {
40- //Canonical links look like this: http://docs.aws.amazon.com/sdkfornet/v4/apidocs/index.html?page=PAGE.html&tocid=TOCID
41- //Attempt to find where the relative path starts after the hostname.
42- var seekFrom = 0 ;
43- var protocolEndIndex = pageLink . indexOf ( '://' ) ;
44- if ( protocolEndIndex != - 1 ) {
45- seekFrom = protocolEndIndex + 3 ;
46- }
34+ //This content page is not in the expected frameset which contains the TOC so
35+ //reload the parent frame and cause it to reload this page in the frame.
36+ //Read the tocid from the meta tag and build the frameset URL.
37+ var tocid = jQuery ( "meta[name='aws-tocid']" ) . attr ( 'content' ) ;
38+ var pathname = window . location . pathname ;
39+ var itemsIndex = pathname . indexOf ( '/items/' ) ;
4740
48- //Look for the start of the relative path.
49- var relPathIndex = pageLink . indexOf ( '/' , seekFrom ) ;
50- if ( relPathIndex != - 1 ) {
51- //Reload the parent frameset and this content page. Note the address bar URL will
52- //look like the canonical link in the address bar. The inFrame part of this script
53- //will run on release to replace the address bar URL with the actual friendly content
54- //frame page URL.
55- window . location . href = pageLink . substring ( relPathIndex ) ;
56- }
57- //Else do nothing because the link doesn't appear to be in a normal URL format where the
58- //hostname ends with a / starting the relative URL path.
41+ if ( tocid && itemsIndex !== - 1 ) {
42+ //Build the frameset URL from the current path
43+ var basePath = pathname . substring ( 0 , itemsIndex ) ;
44+ var filename = pathname . substring ( pathname . lastIndexOf ( '/' ) + 1 ) ;
45+ //Reload the parent frameset and this content page. The inFrame part of this script
46+ //will run on reload to replace the address bar URL with the actual friendly content
47+ //frame page URL.
48+ window . location . href = basePath + '/index.html?page=' + filename + '&tocid=' + tocid ;
5949 }
6050 }
6151} ) ( ) ;
0 commit comments