実現したいこと
javascriptを動かしたい
前提
vscodeでオフライン上でjavascriptを記述して動かそうとするも動かないので困っています。
参考書を元に行い構文チェックもしました。
該当のソースコード
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script> var script = document.createElement('script'); //変数名は適当なものにでも script.src = "import.js"; //ファイルパス document.head.appendChild(script); </script> <style> body { font-size: 14pt; font-weight: plain;} h1 { color: white; padding: 5px; font-size: 24pt; background-color: red;} #msg {background-color: #ffaaaa; margin: 0; position: absolute; width: 100px; height: 100px; top: 50px; left: 50px; cursor: pointer;} </style> <script> function doDown(event){ if (event.target.id == 'msg'){event.target.style.backgroundcolor = '#cc7777';} } function doup(event){ if (event.currentTarget.id == 'msg'){ event.target.style.backgroundcolor = '#ffaaaa'; } } function domove(event){ if (evet.target.id == 'msg'){ if (event.buttons == 1){ var w = event.ClientX; var h = event.ClientY; event.target.style.left = (w - 50) + 'px'; event.target.style.top = (h - 50) + 'px'; } } } </script> </head> <body> <h1 id="Title">Hello</h1> <p id="msg" onmousedown="doDown(event);" onmouseUp="doUp(event);" onmouseMove="doMove(event);">マウスでドラッグしてみよう</p> </body> </html>
試したこと
ブラウザのjavascript設定は有効で最新バージョンです。サイト検索で動かない原因を調べましたがわかりません。動ないコードはこの限りではありません。> 引用テキスト
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
>参考書を元に行い構文チェックもしました。
構文チェックではなくブラウザの開発者ツールでエラーが出ていないか確認するのが先です。
https://willcloud.jp/knowhow/dev-tools-01/
御回答ありがとうございます。検証で調べたら初めの1行目が出てgoogleで調べた後、次々にエラーが出てきました。
Failed to load resource: net::ERR_FILE_NOT_FOUND
5Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('file://') does not match the recipient window's origin ('null').
VM33 check.js:1 Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('file://') does not match the recipient window's origin ('null').
P @ VM33 check.js:1
t.exports @ VM33 check.js:1
2cf4 @ VM33 check.js:1
e @ VM33 check.js:1
e6cf @ VM33 check.js:1
e @ VM33 check.js:1
810a @ VM33 check.js:1
e @ VM33 check.js:1
3 @ VM33 check.js:1
e @ VM33 check.js:1
(匿名) @ VM33 check.js:1
(匿名) @ VM33 check.js:1
VM34 check.js:1 Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('file://') does not match the recipient window's origin ('null').
P @ VM34 check.js:1
t.exports @ VM34 check.js:1
2cf4 @ VM34 check.js:1
e @ VM34 check.js:1
e6cf @ VM34 check.js:1
e @ VM34 check.js:1
810a @ VM34 check.js:1
e @ VM34 check.js:1
3 @ VM34 check.js:1
e @ VM34 check.js:1
(匿名) @ VM34 check.js:1
(匿名) @ VM34 check.js:1
VM35 check.js:1 Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('file://') does not match the recipient window's origin ('null').
P @ VM35 check.js:1
t.exports @ VM35 check.js:1
2cf4 @ VM35 check.js:1
e @ VM35 check.js:1
e6cf @ VM35 check.js:1
e @ VM35 check.js:1
810a @ VM35 check.js:1
e @ VM35 check.js:1
3 @ VM35 check.js:1
e @ VM35 check.js:1
(匿名) @ VM35 check.js:1
(匿名) @ VM35 check.js:1
VM36 check.js:1 Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('file://') does not match the recipient window's origin ('null').
P @ VM36 check.js:1
t.exports @ VM36 check.js:1
2cf4 @ VM36 check.js:1
e @ VM36 check.js:1
e6cf @ VM36 check.js:1
e @ VM36 check.js:1
810a @ VM36 check.js:1
e @ VM36 check.js:1
3 @ VM36 check.js:1
e @ VM36 check.js:1
(匿名) @ VM36 check.js:1
(匿名) @ VM36 check.js:1
check.js:1 Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('file://') does not match the recipient window's origin ('null').
P @ check.js:1
t.exports @ check.js:1
2cf4 @ check.js:1
e @ check.js:1
e6cf @ check.js:1
e @ check.js:1
810a @ check.js:1
e @ check.js:1
3 @ check.js:1
e @ check.js:1
(匿名) @ check.js:1
(匿名) @ check.js:1
<script>
doDown, doup, domove
<p>
doDown, doUp ,doMove
他にも大文字小文字は区別なく使えるのでしょうか?
scriptタグをわざわざcreateしている意図は?
あとhttpアクセスではどうでしょう
あなたの回答
tips
プレビュー