2012-12-12 48 views
0

我有以下網頁,當我從本地計算機瀏覽器中查看時,顯示的內容完全按照我的意圖顯示。但是,在將該頁面複製到服務器上的文件存儲(以及所需的所有支持文件)後,通過瀏覽到它所在的URL來查看它,我發現它不顯示在相同的位置就像從本地計算機上查看它一樣。當從本地機器瀏覽器中查看時,網頁顯示與從服務器瀏覽器中查看時的顯示不同

我的頁面是:

<!DOCTYPE HTML> 
<html> 
<head> 
<style> 
    body { 
    margin: 0px; 
    padding: 0px; 
    } 
    canvas{ 
    border: 1px solid #9C9898; 
    background:#F5F5F5; 
    } 
</style> 
<div id="container"></div> 
<script src="http://www.html5canvastutorials.com/libraries/kinetic-v4.1.2.js"></script> 
<script src="drawDescriptionBoxes.js"></script> 
<script> 
/*Add the game elements' global variables */ 
var currentLevel = 1; 
var totalLevels = 3; 
var currentScore = 0; 
var currentScorePositionX = 950; 
var currentScorePositionY = 10; 

/*Add code to draw images to random locations here */ 
    var imageX = Math.floor(Math.random()*950); 
    var imageY = Math.floor(Math.random()*450); 

    var stage = new Kinetic.Stage({ 
     container: "container", 
     width: 1000, 
     height: 500 
    }); 
    var imagesLayer = new Kinetic.Layer(); 
    var canvas = imagesLayer.getCanvas(); 
    var context = canvas.getContext("2d"); 
    console.log("Foo "); 

function loadImages(sources, callback){ 
    var imagesDir = ""; 
    var images = {}; 
    var loadedImages = 0; 
    var numImages = 0; 

    //console.log("length " + sources.length); 
    for (var src in sources){ 
     numImages++; 
    } 
    //console.log("Num Images " + numImages); 

    var index=0; 
    console.log("length " + sources.length); 
    for (index=0;index < numImages ;index++){ 
     console.log(index); 
     images[index] = new Image(); 
     images[index].src = sources[index]; 
     console.log("Adding " + sources[index]); 
     callback(images[index]); 
     console.log("images array length = " + images.length); 
    } 

    stage.add(imagesLayer); // should only be added once!! 
    } 

    function isNearDescriptionBox(itemImage, descriptionBox){ 
     var ii = itemImage; 
     var db = descriptionBox; 
     if(ii.attrs.x > db.x - 20 && ii.attrs.x < db.x + 20 && ii.attrs.y > db.y - 20 && ii.attrs.y < db.y +20){ 
      return true; 
     }else{ 
      return false; 
     } 
    } 

    /* This function draws the game elements */ 
    function drawGameElements(){ 
     /* Draw a line for the 'score bar'. */ 
     context.moveTo(0, 25); 
      context.lineTo(1000, 25); 
     context.stroke(); 

     /* Draw current level/ total levels on the left, and current score on the right. */ 
     context.font = "11pt Calibri"; /* Text font & size */ 
     context.strokeStyle = "black"; /* Font colour */ 
     context.strokeText(currentLevel + "/" + totalLevels, 10, 15); 
     context.strokeText(currentScore, 750, 15); 
    } 

    function initStage(images){ 
     var stage = new Kinetic.Stage({ 
      container: "container", 
      width: 1000, 
      height: 500 
     }); 
     var descriptionLayer = new Kinetic.Layer(); 
     //var imagesLayer = new Kinetic.Layer(); 
     var allImages = []; 
     var currentScore = 0; 




     /*Draw the description boxes */ 

    } 

    function drawImage(imageObj) { 
    //var layer = new Kinetic.Layer(); 

    var canvasImage = new Kinetic.Image({ 
     image: imageObj, 
     width: 50, 
     height: 50, 
      // puts the image in teh middle of the canvas 
      x: stage.getWidth()/2 - 50/2, 
     y: stage.getHeight()/2 - 50/2, 
     draggable: true 
    }); 

    // add cursor styling 
    canvasImage.on('mouseover', function() { 
     document.body.style.cursor = 'pointer'; 
    }); 
    canvasImage.on('mouseout', function() { 
     document.body.style.cursor = 'default'; 
    }); 

    imagesLayer.add(canvasImage); 
    } 

    /*This code loads the images to the canvas when the browser window loads */ 
    window.onload = function(){ 
     var sources = {}; 
      sources[0] = document.getElementById("building").src, 
      sources[1] = document.getElementById("chair").src, 
      sources[2] = document.getElementById("drink").src, 
      sources[3] = document.getElementById("food").src, 
      sources[4] = document.getElementById("fridge").src, 
      sources[5] = document.getElementById("land").src, 
      sources[6] = document.getElementById("money").src, 
      sources[7] = document.getElementById("oven").src, 
      sources[8] = document.getElementById("table").src, 
      sources[9] = document.getElementById("van").src, 

      sources[10] = document.getElementById("burger").src, 
      sources[11] = document.getElementById("chips").src, 
      sources[12] = document.getElementById("drink").src, 
      sources[13] = document.getElementById("franchiseFee").src, 
      sources[14] = document.getElementById("wages").src, 

      sources[15] = document.getElementById("admin").src, 
      sources[16] = document.getElementById("cleaners").src, 
      sources[17] = document.getElementById("electricity").src, 
      sources[18] = document.getElementById("insurance").src, 
      sources[19] = document.getElementById("manager").src, 
      sources[20] = document.getElementById("rates").src, 
      sources[21] = document.getElementById("training").src, 
      sources[22] = document.getElementById("water").src, 

      sources[23] = document.getElementById("burger").src, 
      sources[24] = document.getElementById("chips").src, 
      sources[25] = document.getElementById("drink").src, 

      sources[26] = document.getElementById("creditors").src, 
      sources[27] = document.getElementById("electricity").src, 
      sources[28] = document.getElementById("food").src, 
      sources[29] = document.getElementById("hirePurchase").src, 
      sources[30] = document.getElementById("loan").src, 
      sources[31] = document.getElementById("overdraft").src, 
      sources[32] = document.getElementById("payeTax").src, 
      sources[33] = document.getElementById("tax").src 

     loadImages(sources, drawImage); 
     drawGameElements(); 
     drawDescriptionBoxes(); 
    }; 


    </script> 


</head> 
<body> 

<section hidden> 
<img id="startButton" src="images/startButton.png" alt="Start Button" width="179" height="180" href="javascript:drawLevelOneElements();"/> 
<img id="box" src="images/box.png" alt="box.png" alt="Description Box" width="100" height="50" /> 

<img id="building" src="images/assets/building.png" alt="Asset" /> 
<img id="chair" src="images/assets/chair.gif" alt="Asset" /> 
<img id="drink" src="images/assets/drink.jpg" alt="Asset" /> 
<img id="food" src = "images/assets/food.gif" alt="Asset"/> 
<img id="fridge" src = "images/assets/fridge.png" alt="Asset"/> 
<img id="land" src = "images/assets/land.jpg" alt="Asset"/> 
<img id="money" src = "images/assets/money.jpg" alt="Asset"/> 
<img id="oven" src = "images/assets/oven.jpg" alt="Asset"/> 
<img id="table" src = "images/assets/table.gif" alt="Asset"/> 
<img id="van" src = "images/assets/van.jpg" alt="Asset"/> 

<img id="burger" src = "images/expenses/direct/burger.png" alt="Direct Expense"/> 
<img id="chips" src = "images/expenses/direct/chips.png" alt="Direct Expense"/> 
<img id="drink" src = "images/expenses/direct/drink.jpg" alt="Direct Expense"/> 
<img id="franchiseFee" src = "images/expenses/direct/franchiseFee.jpg" alt="Direct Expense"/> 
<img id="wages" src = "images/expenses/direct/wages.jpg" alt="Direct Expense"/> 

<img id="admin" src = "images/expenses/indirect/admin.jpg" alt="Indirect Expense"/> 
<img id="cleaners" src = "images/expenses/indirect/cleaners.gif" alt="Indirect Expense"/> 
<img id="electricity" src = "images/expenses/indirect/electricity.gif" alt="Indirect Expense"/> 
<img id="insurance" src = "images/expenses/indirect/insurance.jpg" alt="Indirect Expense"/> 
<img id="manager" src = "images/expenses/indirect/manager.jpg" alt="Indirect Expense"/> 
<img id="rates" src = "images/expenses/indirect/rates.jpg" alt="Indirect Expense"/> 
<img id="training" src = "images/expenses/indirect/training.gif" alt="Indirect Expense"/> 
<img id="water" src = "images/expenses/indirect/water.gif" alt="Indirect Expense"/> 

<img id="burger" src = "images/income/burger.png" alt="Income"/> 
<img id="chips" src = "images/income/chips.png" alt="Income"/> 
<img id="drink" src = "images/income/drink.jpg" alt="Income"/> 

<img id="creditors" src = "images/liabilities/creditors.gif" alt="Liability"/> 
<img id="electricity" src = "images/liabilities/electricity.png" alt="Liability"/> 
<img id="food" src = "images/liabilities/food.jpg" alt="Liability"/> 
<img id="hirePurchase" src = "images/liabilities/hirePurchase.jpg" alt="Liability"/> 
<img id="loan" src = "images/liabilities/loan.png" alt="Liability"/> 
<img id="overdraft" src = "images/liabilities/overdraft.jpg" alt="Liability"/> 
<img id="payeTax" src = "images/liabilities/payeTax.jpg" alt="Liability"/> 
<img id="tax" src = "images/liabilities/tax.jpg" alt="Liability"/> 


</section> 
</body> 
</html> 

當我在本地查看它,它會顯示一個畫布,與被抽通過以下功能四個「描述盒子」這是一個從JavaScript調用頁面上(雖然功能本身實際上是在一個單獨的JS文件):

CanvasRenderingContext2D.prototype.drawDescriptionArea = function(x, y, width, height, radius, stroke){ 
     if(typeof stroke == "undefined"){ 
      stroke = true; 
     } 
     if(typeof radius === "undefined"){ 
      radius = 5; 
     } 
     this.beginPath(); 
     this.moveTo(x + radius, y); 
     this.lineTo(x + width - radius, y); 
     this.quadraticCurveTo(x + width, y, x + width, y + radius); 
     this.lineTo(x + width, y + height - radius); 
     this.quadraticCurveTo(x + width, y + height, x + width - radius, y + height); 
     this.lineTo(x + radius, y + height); 
     this.quadraticCurveTo(x, y + height, x, y + height - radius); 
     this.lineTo(x, y + radius); 
     this.quadraticCurveTo(x, y, x + radius, y); 
     this.closePath(); 
     if(stroke){ 
      context.stroke(); 
     } 
    } 

    context.drawDescriptionArea(70, 400, 120, 70); 
    context.font = '25pt Calibri'; 
    context.strokeText('Asset', 90, 440); 

    context.drawDescriptionArea(300, 400, 120, 70); 
    context.strokeText('Liability', 310, 440); 

    context.drawDescriptionArea(540, 400, 120, 70); 
    context.strokeText('Income', 550, 440); 

    context.drawDescriptionArea(750, 400, 180, 70); 
    context.strokeText('Expenditure', 760, 440); 

然而,當我看到它使用在其中它位於URL中的服務器,出於某種原因,說明框不會顯示在畫布,我不明白爲什麼,因爲我已經複製一切從我的本地機器到服務器,所以它應該都在那裏。

任何人有任何想法?這裏指定

+1

你是否在本文件中運行''?你可以在你的瀏覽器中確認文件實際加載了嗎? –

+0

是的,該功能在該文件中。我不確定你是什麼意思?我將如何驗證文件是否實際加載?它顯示在我的本地機器上查看它(即通過右鍵單擊index.html文件並在瀏覽器中打開它),這意味着它必須加載JS文件...並且我已經複製了所有內容從我的本地機器到服務器,所以我希望它的功能完全一樣 – someone2088

+0

我的意思是,如果你使用Firebug或類似的,你可以看看實際的網絡信息,看看你收到的文件與200響應。 –

回答

0

JavaScript文件中:

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

沒有加載。

在上面的註釋中進行了討論,這是因爲文件名在源代碼中存在大小寫問題。

相關問題