Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从另一个文件获取数据_Javascript_Html - Fatal编程技术网

Javascript 从另一个文件获取数据

Javascript 从另一个文件获取数据,javascript,html,Javascript,Html,我想将hello.html上标记中的数据获取到index.html。我该怎么做 index.html: //一些代码 hello.html: <html> <head> </head> <body> <script> document.writeln("hello world"); </script> </body> </html> 书面文件(“你好世界”); 编辑:我想要“docu

我想将hello.html上
标记中的数据获取到index.html。我该怎么做

index.html:


//一些代码
hello.html:

<html>

<head>
</head>

<body>
<script>
document.writeln("hello world");
</script>
</body>

</html>

书面文件(“你好世界”);

编辑:我想要“document.writeln(“hello world”);”部分,它必须是字符串。

将脚本单独保存为
myScript.js
,然后您可以在两个html文件中使用它和脚本include标记

将脚本移动到新文件中,例如
script.js
,然后将其添加到两个文件中:

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


您最好将脚本移出到外部文件,然后可以在两个.html文件中都有
。否则,你要做的事情几乎是不可能的。我同意影子巫师的观点@doruk您的问题不清楚,如果您想使用javascript将数据从一个页面发送到另一个页面,请使用带有查询字符串值的重定向。问题已添加编辑。我想要脚本的“document.writeln(“helloworld”);”部分,它必须是字符串。
<script src="script.js"></script>