Javascript 不使用 XAMPP 执行 [英] Javascript not executing using XAMPP
问题描述
在我的 html 文档(位于 xampp/htdocs
目录中)中,我使用的是外部 .js 文件..js 文件与我的 html 文件位于同一目录中.我只是想使用 document.write()
函数,但它没有打印任何内容.
我不明白我做错了什么.这是什么问题?
HTML 文件
<头><?php 包含 'include/head_elements.html'?><script type="text/javascript" src="register.js"></script>头部><身体><h1>公司帐户创建</h1><div id="registration_menu"><!--使用JS动态添加和删除元素-->
<脚本>你好();load_element_group("email_verification");</html>
JS文件
函数hello(){document.write("你好世界")}
Internet Explorer 的安全策略可能会阻止某些脚本在本地计算机上运行.
有一些方法可以避免这种情况——例如通过将 XAMPP 网站添加为受信任的位置——但这通常会变得棘手,因为默认的Intranet 区域"是在 PC 上自动配置的,修改它可能会产生其他后果(不同的区域采用不同的设置,例如将 NTLM 凭据传递给本地网站).
另见
In my html document (which is in the xampp/htdocs
directory), I'm using an external .js file. The .js file is in the same directory as my html file. I'm simply trying to use document.write()
function and it's not printing anything.
I don't understand what I'm doing wrong. Whats the issue?
HTML file
<!DOCTYPE html>
<html>
<head>
<?php include 'include/head_elements.html'?>
<script type="text/javascript" src="register.js"></script>
</head>
<body>
<h1>Company Account creation</h1>
<div id="registration_menu">
<!--Elements are added and removed dynamically using JS-->
</div>
<script>
hello();
load_element_group("email_verification");
</script>
</body>
</html>
JS file
function hello(){
document.write("Hello world")
}
Internet Explorer's security policy may block certain scripts from running on a local machine.
There are ways to avoid this -- such as by adding the XAMPP website as a trusted location -- but often this gets tricky since the default "Intranet Zone" is auto-configured on a PC and modifying that can have other consequences (different zones assume different settings, such as passing NTLM credentials to local websites).
See also https://stackoverflow.com/a/7038775/3196753
A quick fix often is to add the fully qualified domain name (FQDN) to the URL, but depending on the zone settings, this may still cause issues.
A final solution, and one many developers fall back on, is to actually use a registered DNS address, such as http://localtest.me/, which points back to localhost and should use the "Internet Zone".
As Chris G
points out in the comments, this isn't typical. Normally localhost
can be used without issue so I've provided an example Local Intranet
setting which can cause this:
这篇关于Javascript 不使用 XAMPP 执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!