我的目标是将这个javascript代码放入wordpress php,我不知道如何在不收到错误消息的情况下这样做。最终目标是将javascript游戏简单地嵌入wordpress页面。我已经检查过其他几十篇文章,但没有一篇对这样的代码足够具体。我想要包含在php中的代码仅在虚拟网站链接下面。希望你能帮助我!提前谢谢。
<script src="http://www.java.com/js/deployJava.js"></script>
<script>
var attributes = {
codebase: 'my_website',
code: 'vNES.class',
archive: 'my_website',
width: 512,
height: 480
};
var parameters = {
sound: "on",
timeemulation: "on",
fps: "off",
stereo: "off",
rom: "my_website/game.zig",
showsoundbuffer: "off",
scale: "on",
scanlines: "off",
nicesound: "on",
romsize: 40976
};
deployJava.setInstallerType('online');
// deployJava.setInstallerType('kernel');
if (deployJava.versionCheck('1.5+')) {
deployJava.runApplet(attributes, parameters, '1.5');
} else {
document.write("<br />");
document.write("<b style='color: red;'>Your browser does not appear to have Java installed.</b>");
document.write("<b><a href='#' onclick='javascript:deployJava.installLatestJRE();'>Click here to install the Java run-time.</a></b><br /><br />");
if (navigator.userAgent.indexOf("Chrome") != -1 && navigator.userAgent.indexOf("Mac OS X") != -1) {
document.write("<b style='color: red;'>");
document.write("Please note that Google Chrome under MacOS X does currently not support Java applets, so consider temporarily switching to Firefox or Safari if you are a MacOS X user.<br /><br />");
document.write("</b>");
}
document.write("This page has been tested and works with the latest versions of the following Windows browsers: Firefox, Google Chrome, Internet Explorer, Opera and Safari.<br /><br />");
document.write("This page has been tested and works with the latest versions of the following MacOS X browsers: Firefox, Opera and Safari.<br /><br />");
}
</script>
答案 0 :(得分:0)
您可以发布您收到的错误消息吗?根据我对wordpress的经验,这应该是非常直接的。在wordpress你想要这个出现在哪里?在索引页面上?
如果是这种情况,您可以回显每一行,或者只是通过关闭和打开php标记来转义脚本。这个想法与上面的document.write(“...”);
相同只需要逃避“标记
echo"<script src=\"http://www.java.com/js/deployJava.js\"></script>";
也...可以添加如下代码
<?php (php code...) ?>
<script type="text/javascript">
window.location = "http://www.google.com/"
</script>
<?php (php code continues...) ?>
希望这会有所帮助。在wordpress中,我会进入文件并编辑索引文件,但也取决于你想在wordpress中放置它的位置。无论哪种方式,您都必须编辑文件才能使其正常工作。
您还可以在wordpress中添加新页面...
在主题文件夹中复制post.php(在/ wp-content / themes / themename /)下。
将文件重命名为someNameYouWant.php
现在在顶部添加:
<?php
/*
Template Name: templatename
*/
?>
您可以修改此文件(使用php)以包含其他文件或任何您需要的文件。
然后在wordpress博客中创建一个新页面,在页面编辑屏幕中,您将在右侧的“属性”小部件中看到“模板”下拉列表。选择新模板并发布页面。
您的新页面将使用templatename.php中定义的php代码