2013-06-21 2 views
2

외부 URL을로드하지 못했습니다, 내가 얻을 :가 (Google 사이트에서 호스팅) 내 웹 페이지에 자바 스크립트 코드를 삽입하는 중에 Google 사이트

Failed to load external url 

또는이 :

enter image description here

자바 스크립트 파일은 내 웹 페이지 (MyCabbinet 섹션에 있음)에서 호스팅됩니다.

하지만 내 페이지에도 동일한 결과가 계속 나타납니다.

코드는 :

<!doctype html> 
<html lang="en"> 

<head> 
<meta charset="UTF-8"> 

<style type="text/css"> 
h4 {font-family: sans-serif;} 
p {font-family: sans-serif;} 
a {font-family: sans-serif; color:#d15423; text-decoration:none;} 
</style> 


<title>HTML5 Canvas Example - Simple Dragging Objects</title> 

<script src="https://sites.google.com/site/bestbookreviewever/mycabinet/modernizr-2.0.6.js"></script> 

<script type="text/javascript"> 

//JavaScript HTML5 Canvas example by Dan Gries, rectangleworld.com. 
//The basic setup here, including the debugging code and window load listener, is copied from 'HTML5 Canvas' by Fulton & Fulton. 
//Checking for browser compatibility is accomplished with the Modernizr JavaScript library. 
//The latest version of the library is available at www.modernizr.com. 

//The code below establishes a way to send debug messages to the browser JavaScript Console, 
//but in such a way as to ignore errors when the browser doesn't support the JavaScript Console. 
//To log a messages to the console within this code, insert into the code: 
//Debugger.log("my message"); 
window.addEventListener("load", windowLoadHandler, false); 
var Debugger = function() { }; 
Debugger.log = function(message) { 
try { 
    console.log(message); 
} 
catch (exception) { 
    return; 
} 
} 

function windowLoadHandler() { 
canvasApp(); 
} 

function canvasSupport() { 
return Modernizr.canvas; 
} 

function canvasApp() { 
if (!canvasSupport()) { 
    return; 
} 

var theCanvas = document.getElementById("canvasOne"); 
var context = theCanvas.getContext("2d"); 

init(); 

var numShapes; 
var shapes; 
var dragIndex; 
var dragging; 
var mouseX; 
var mouseY; 
var dragHoldX; 
var dragHoldY; 

function init() { 
    numShapes = 10; 
    shapes = []; 

    makeShapes(); 

    drawScreen(); 

    theCanvas.addEventListener("mousedown", mouseDownListener, false); 
} 

function makeShapes() { 
    var i; 
    var tempX; 
    var tempY; 
    var tempRad; 
    var tempR; 
    var tempG; 
    var tempB; 
    var tempColor; 
    for (i=0; i < numShapes; i++) { 
    tempRad = 10 + Math.floor(Math.random()*25); 
    tempX = Math.random()*(theCanvas.width - tempRad); 
    tempY = Math.random()*(theCanvas.height - tempRad); 
    tempR = Math.floor(Math.random()*255); 
    tempG = Math.floor(Math.random()*255); 
    tempB = Math.floor(Math.random()*255); 
    tempColor = "rgb(" + tempR + "," + tempG + "," + tempB +")"; 
    tempShape = {x:tempX, y:tempY, rad:tempRad, color:tempColor}; 
    shapes.push(tempShape); 
    } 
} 

function mouseDownListener(evt) { 
    var i; 
    //We are going to pay attention to the layering order of the objects so that if a mouse down occurs over more than object, 
    //only the topmost one will be dragged. 
    var highestIndex = -1; 

    //getting mouse position correctly, being mindful of resizing that may have occured in the browser: 
    var bRect = theCanvas.getBoundingClientRect(); 
    mouseX = (evt.clientX - bRect.left)*(theCanvas.width/bRect.width); 
    mouseY = (evt.clientY - bRect.top)*(theCanvas.height/bRect.height); 

    //find which shape was clicked 
    for (i=0; i < numShapes; i++) { 
    if (hitTest(shapes[i], mouseX, mouseY)) { 
    dragging = true; 
    if (i > highestIndex) { 
    //We will pay attention to the point on the object where the mouse is "holding" the object: 
    dragHoldX = mouseX - shapes[i].x; 
    dragHoldY = mouseY - shapes[i].y; 
    highestIndex = i; 
    dragIndex = i; 
    } 
    } 
    } 

    if (dragging) { 
    window.addEventListener("mousemove", mouseMoveListener, false); 
    } 
    theCanvas.removeEventListener("mousedown", mouseDownListener, false); 
    window.addEventListener("mouseup", mouseUpListener, false); 

    //code below prevents the mouse down from having an effect on the main browser window: 
    if (evt.preventDefault) { 
    evt.preventDefault(); 
    } //standard 
    else if (evt.returnValue) { 
    evt.returnValue = false; 
    } //older IE 
    return false; 
} 

function mouseUpListener(evt) { 
    theCanvas.addEventListener("mousedown", mouseDownListener, false); 
    window.removeEventListener("mouseup", mouseUpListener, false); 
    if (dragging) { 
    dragging = false; 
    window.removeEventListener("mousemove", mouseMoveListener, false); 
    } 
} 

function mouseMoveListener(evt) { 
    var posX; 
    var posY; 
    var shapeRad = shapes[dragIndex].rad; 
    var minX = shapeRad; 
    var maxX = theCanvas.width - shapeRad; 
    var minY = shapeRad; 
    var maxY = theCanvas.height - shapeRad; 
    //getting mouse position correctly 
    var bRect = theCanvas.getBoundingClientRect(); 
    mouseX = (evt.clientX - bRect.left)*(theCanvas.width/bRect.width); 
    mouseY = (evt.clientY - bRect.top)*(theCanvas.height/bRect.height); 

    //clamp x and y positions to prevent object from dragging outside of canvas 
    posX = mouseX - dragHoldX; 
    posX = (posX < minX) ? minX : ((posX > maxX) ? maxX : posX); 
    posY = mouseY - dragHoldY; 
    posY = (posY < minY) ? minY : ((posY > maxY) ? maxY : posY); 

    shapes[dragIndex].x = posX; 
    shapes[dragIndex].y = posY; 

    drawScreen(); 
} 

function hitTest(shape,mx,my) { 

    var dx; 
    var dy; 
    dx = mx - shape.x; 
    dy = my - shape.y; 

    //a "hit" will be registered if the distance away from the center is less than the radius of the circular object 
    return (dx*dx + dy*dy < shape.rad*shape.rad); 
} 

function drawShapes() { 
    var i; 
    for (i=0; i < numShapes; i++) { 
    context.fillStyle = shapes[i].color; 
    context.beginPath(); 
    context.arc(shapes[i].x, shapes[i].y, shapes[i].rad, 0, 2*Math.PI, false); 
    context.closePath(); 
    context.fill(); 
    } 
} 

function drawScreen() { 
    //bg 
    context.fillStyle = "#000000"; 
    context.fillRect(0,0,theCanvas.width,theCanvas.height); 

    drawShapes(); 
} 

} 

</script> 

</head> 
<body> 
<div style="top: 50px; text-align:center"> 
<h4>A Simple HTML5 Canvas Example - Dragging Objects</h4> 
<canvas id="canvasOne" width="500" height="300"> 
Your browser does not support HTML5 canvas. 
</canvas> 
<p>Drag the circles with the mouse.</p> 
<p><a href="http://www.rectangleworld.com">rectangleworld.com</a></p> 
</div> 
</body> 
</html> 

어떤 생각 방법이 문제를 해결하려면?

+0

'url'로 가보면 파일 내용이 표시되지 않는 것을 볼 수 있습니다. 이것이 문제입니다. 그냥'http : //'로 다운로드 할 파일을 제공하고'text/javascript' 파일로 제공하지 않습니다. –

+0

@NickR : 아하, 알았어. 이 주변의 어떤 방법? – ron

+0

파일을 다른 곳에 보관 하시겠습니까? 저는 Google 사이트 도구에 익숙하지 않지만 http://productforums.google.com/forum/#!topic/sites/-dei7Nm5o6o는 귀하에게 어떤 가치가 있는지를 알지 못합니다. –

답변

1

url으로 가려고하면 파일 내용이 표시되지 않는 것을 볼 수 있습니다. 이것이 문제입니다. 단지 http://로 그것은 serving up 다운로드 할 파일, 그리고 다른 곳에 text/javascript

호스트로 파일을 그것을 제공하지? 저는 Google 사이트 도구에 익숙하지 않지만 다음을 찾았습니다. productforums.google.com/forum/#!topic/sites/-dei7Nm5o6o 당신에게 어떤 가치가 있는지 알 수 없습니다.