title: How to display either image (img) or pdf (iframe)?
body: <p>Dynamic links I display on my page (rest) may result in jpeg, tif or pdf file in the response.</p>
  
  <p>I tried to do it like this (the images part works fine):</p>
  
  <pre><code>fetchContent(uri){
      $.ajax({ 
          type: "GET",            
          url: uri,
  
          success: function(output, status, xhr) {
              var contentType = xhr.getResponseHeader("Content-Type");
  
              if(contentType === "image/jpeg" || contentType === "image/tiff"){
  
                  // IMG: get parent div 'container'
                  var $container = $('#container', top.frames["content"].document);
                  var img = new Image();
  
                  $(img)
                      .load(function(){
                          // initially hide
                          $(this).hide();
                          $(this).attr('id', 'imgId');
  
                          // parent div:
                          $container
                              // remove previous image
                              .empty()
                              // add this image
                              .append(this);
  
                          // fade in image effect
                          $(this).fadeIn();
  
                      })
  
                      // set the src attribute of the new image to our image
                      .attr('src', uri);
  
              }else if(contentType === "application/pdf"){
                  // PDF: get parent div 'main'
                  var $main = $('#main', top.frames["content"].document);
  
                  $main.empty();
                  $main.append("&lt;iframe id='contentIFrame' name='contentIFrame' src='" + uri +
                  "' width='100%' style='height:100%'&gt;&lt;/iframe&gt;");
              }
          },
          complete: function(output){
              $('#navigation-block').append(output);
          },
  
          error: function(output) {
              $('#navigation-block').append(output);
          }
      });
  }
  </code></pre>
  
  <p>The PDF part doesn't work.</p>
  
  <p>How do I sort that out?</p>
  
  <p>BTW, I control both REST server side and jQuery side so I added correct content-type in REST response header.</p>
  
  <p>I checked out PDF.js and would have used it, but my client unfortunately uses IE8.</p>
  
  <p>Thanks</p>