Question

I'm trying to get my links in currmenu div to do the following. I need them to change the value of the URL that is in the javascript. Then have the script load the new page into the pdf div.

All the files I link will be internal and on the company intranet. I have to use the preexisting site and add this new feature. Any and all help will be greatly appreciated.

<link href="css/pdf.css" rel="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-latest.min.js"
    type="text/javascript"></script>
<script type="text/javascript" src="js/pdfobject.js"></script>
<script type="text/javascript">

window.onload = function (){

    var msg;
    var s = document.getElementById("statement");   
    var params = { 

        url: "Docs/6-Week Calendar.pdf",

        pdfOpenParams: {

            navpanes: 0,
            toolbar: 0,
            statusbar: 0,
            view: "FitV"

        }

    };

    var myPDF = new PDFObject(params).embed("pdf");

    if(myPDF){
        msg = "The PDF was successfully embedded!";
        s.className = "success";
    } else {
        msg = "It appears the embed didn't work.";
        s.className = "fail";
    }
            s.innerHTML = msg;
    };
</script>

</head>
<body>
   <div class="currmenulist">
   <li><a href="Docs/New Employee onboarding curriculum.pdf">Link 1</a></li>
                            <li><a href="">Link 2</a></li>
                            <li><a href="">Link 3</a></li>
                            <li><a href="">Link 4</a></li>

 </div>  
<div id="pdf">It appears you don't have Adobe Reader or PDF support in this web 
browser. <a href="Docs/6-Week Calendar.pdf">Click here to download the PDF</a></div> <p 
id="statement"> </p>  

</body>
Était-ce utile?

La solution

This code will work for you

window.onload = function () {

   var params = {
         url: "Docs/6-Week Calendar.pdf",
         pdfOpenParams: {
            navpanes: 0,
            toolbar: 0,
            statusbar: 0,
            view: "FitV"
         }
      },
      s = document.getElementById("statement");

   function loadPDF() {
      var msg,
          myPDF = new PDFObject(params).embed("pdf");

      if (myPDF) {
         msg = "The PDF was successfully embedded!";
         s.className = "success";
      } 
      else {
         msg = "It appears the embed didn't work.";
         s.className = "fail";
      }
      s.innerHTML = msg;
   }

   var linklist = document.getElementsByClassName('currmenulist')[0],
       pdfLinks = linklist.getElementsByTagName('a');

   for (var k = 0; k < pdfLinks.length; k++) {

      //here you can add validation, i.e, if href ends with .pdf etc
      if (pdfLinks[k].getAttribute('href') == '' || pdfLinks[k].getAttribute('href') == '#')
         continue;

      pdfLinks[k].addEventListener('click', function (ev) {
         ev.preventDefault();

         params.url = ev.target.getAttribute('href');
         loadPDF();
      });
   }

   loadPDF();
};

Autres conseils

This should be what you need:

var msg;
var s = document.getElementById("statement");
var params = { 
    url: "Docs/6-Week Calendar.pdf",
    pdfOpenParams: {
        navpanes: 0,
        toolbar: 0,
        statusbar: 0,
        view: "FitV"
    }
};

window.onload = function (){
    var myPDF = new PDFObject(params).embed("pdf");

    if(myPDF){
        msg = "The PDF was successfully embedded!";
        s.className = "success";
    } else {
        msg = "It appears the embed didn't work.";
        s.className = "fail";
    }
    s.innerHTML = msg;
};

$(".currmenulist a").on("click", function(e){
    e.preventDefault();
    params.url = $(this).attr("href");

    var myPDF = new PDFObject(params).embed("pdf");

    if(myPDF){
        msg = "The PDF was successfully embedded!";
        s.className = "success";
    } else {
        msg = "It appears the embed didn't work.";
        s.className = "fail";
    }
    s.innerHTML = msg;
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top