Wordpress - 如何将HTML / JS添加到多页Post Mobile结尾?

2 Things I'm trying to accomplish I'm hoping someone knows how to do:

  1. Add HTML/JS to the last page at the bottom of all multi-page wordpress posts.
  2. Only show it when a div in the content is 400px or less.

For the mobile part I'm assuming this could be done by getting the width of a div and this is what I have so far. I haven't tried it but it doesn't seem like the best way to accomplish it from what I've read. Problem is I don't know JS.

<div id="mydiv"></div>
 <script type="text/javascript">
    ad = document.getElementById('mydiv');
     if (ad.getBoundingClientRect().width) {
        adWidth = ad.getBoundingClientRect().width; // for modern browsers
    } else {
        adWidth = ad.offsetWidth; // for old IE
    }
     if ( adWidth >= 400 ) {
      document.write('<a href="#"><img src="#"></a>');
             }
    else {
    document.getElementById('mydiv').style.display="none";
    }
</script>

I don't want to use the device screen width and css so I can be sure the content area is a specific size or less unless there's a way to do that that I'm not aware of. I'm not sure how to use the above code either to show the HTML/JS.

Update:

So I had a thought on #1. I currently have wp page navi add a next button to the end of the multi-page post to go to a link I want. Could I somehow incorporate the html/js into that to show above the buttons?

This is the code I'm using for that:

if ( function_exists('wp_pagenavi') )
{
    ob_start();
    wp_pagenavi( array( 'type' => 'multipart' ) );
    $pagenavi = ob_get_contents();
    ob_end_clean();
    if ( !strstr($pagenavi, 'nextpostslink') ) $pagenavi = str_replace('</div>', '<a href="http://link.com" style="float:right;" rel="next" class="nextpostslink">NEXT</a>'."".'</div>', $pagenavi);
    echo $pagenavi;
}

It already shows a back button for the multi-part post so I'm not sure how I could get it on top of that though.