-2

I am creating an offline page flip book.

The javascript links off to a PDF if I am running the site on MAMP local server. But when I try and run the code without being on a local server (desktop) it fails to load the PDF with the error:

XMLHttpRequest cannot load file:///Users/pmdesign7imac/Downloads/wow_book_plugin%202/examples/pdf/pdf_example.pdf. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

Is it possible to link to the file without being on a server?

CODE:

<!DOCTYPE html>
<html class="no-js">
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui,maximum-scale=2">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui,maximum-scale=1">
    <meta http-equiv="cleartype" content="on">

    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="./wow_book/wow_book.css" type="text/css" />
    <link rel="stylesheet" href="css/main.css">

    <script src="js/vendor/modernizr-2.7.1.min.js"></script>
</head>
<body>
    <div class='book_container'>
        <div id="book"></div>
    </div>

    <script src="js/vendor/jquery-1.11.2.min.js"></script>

    <script src="js/helper.js"></script>

    <script type="text/javascript" src="./wow_book/pdf.combined.min.js"></script>
    <script src="./wow_book/wow_book.min.js"></script>
    <script>
        $(function(){
            var bookOptions = {
                 height   : 500
                ,width    : 800
                // ,maxWidth : 800
                ,maxHeight : 600

                ,centeredWhenClosed : true
                ,hardcovers : true
                ,pageNumbers: false
                ,toolbar : "lastLeft, left, right, lastRight, toc, zoomin, zoomout, slideshow, flipsound, fullscreen, thumbnails, download"
                ,thumbnailsPosition : 'left'
                ,responsiveHandleWidth : 50

                ,container: window
                ,containerPadding: "20px"
                ,pdf: "pdf_example.pdf"

            $('#book').wowBook( bookOptions );

        })
    </script>

</body>
</html>
Abanoub Makram
  • 463
  • 2
  • 13
lbollu
  • 269
  • 4
  • 18
  • It's because of the `Http` part in `XMLHttpRequest`. HTTP implies a network. – Álvaro González Apr 20 '17 at 14:02
  • 2
    Possible duplicate of [XMLHttpRequest cannot load file. Cross origin requests are only supported for HTTP](http://stackoverflow.com/questions/20041656/xmlhttprequest-cannot-load-file-cross-origin-requests-are-only-supported-for-ht) – CBroe Apr 20 '17 at 14:24
  • Actually XMLHttpRequest doesn't have to be XML and doesn't have to be HTTP. But code running in a browser cannot, without special arrangements, access filestore in the local machine, for security reasons. – Michael Kay Apr 20 '17 at 15:51

1 Answers1

0

run your website localhost on your local server not as html file opened

Abanoub Makram
  • 463
  • 2
  • 13
  • The whole reason for me running it through the html is that the file will be on a memory stick. It will not have any server. Is there a work around? – lbollu Apr 20 '17 at 14:25
  • you can install local server like xampp or wamp https://www.apachefriends.org/download.html – Abanoub Makram Apr 20 '17 at 14:26
  • Again, this is using a local server. I do not want to use a local server. It needs to run from a memory stick. – lbollu Apr 20 '17 at 14:27
  • read this carefully http://stackoverflow.com/questions/20041656/xmlhttprequest-cannot-load-file-cross-origin-requests-are-only-supported-for-ht – Abanoub Makram Apr 20 '17 at 14:30
  • I understand that I can run the file from a local server on the memory stick. But, I do not want the user to have to start the server up to view the html. They need to be able to just double click the html file. Is that possible? – lbollu Apr 20 '17 at 15:01
  • Also if I install a local server and the person is on a PC instead of mac surely the server would need another form of server? – lbollu Apr 20 '17 at 15:09
  • the local server is required for each PC which website will run on it – Abanoub Makram Apr 20 '17 at 15:30