我一直在慢慢地努力教自己一些关于编码的简单方面。现在,我想将一段JS代码上传到一个页面上。以下是我想要使用的代码的背景:
代码将在一页上进行。此页面是一个表单页面,如果有人做了除了按下"提交"之外的任何其他内容。一个模块弹出一些问题。我一直在使用wordpress。任何想法,指导等都是完美的!
<script>
var config = new Object();
config.surveyID = 3160325;
/*config.animationMode = 0;*/
config.takeSurveyURL = 'http://www.surveyanalytics.com/a/TakeSurvey';
config.windowPositionLeft = 200;
config.windowPositionTop = 300;
config.home = 'http://www.surveyanalytics.com/';
config.isRightToLeft = false;
config.surveyStartMessage = 'Start Survey';
config.popupInvitationLaterMessage = 'Later';
config.showFooter = true;
config.invitationDelay = 0;
config.skipCount = 0;
config.popupMode = 0;
config.expirationTime = 60
window.onbeforeunload = function() {
QP_popupMain();
};
</script>
<script language="javascript" type="text/javascript" src="http://www.surveyanalytics.com//javascript/exitSurveyInvitation.js"></script>
<noscript>
<a href="http://www.supporterfeedback.org/a/TakeSurvey?id=3160325">Start Survey</a> <a href="http://www.surveyanalytics.com/">Survey</a>
</noscript>
答案 0 :(得分:0)
由于WordPress不喜欢functions.php中的<script>
标签,而是将您的代码放入“.js”文件中,并在functions.php中注册脚本,然后将其排入短代码中。
在functions.php
文件中:
add_action( 'wp_enqueue_scripts', 'register_my_script' );
function register_my_script() {
//This example puts it in plugins, but you can put it in your theme instead
wp_register_script( 'script-name', plugins_url( '/js/script.js' , __FILE__ ), array(), '1.0.0', true );
}
//Replace "PUT YOUR JAVASCRIPT CODE IN HERE" with your actual code
function myTestFunction( $atts )
{
//Now enqueue the script
wp_enqueue_script( 'script-name' );
}
add_shortcode( 'myjavascriptfunction', 'myTestFunction' );
然后在CMS中,转到该页面并将调用添加到内容文本框中的短代码中:
[myjavascriptfunction /]
答案 1 :(得分:0)
这是script.js中的代码
<script>
var config = new Object();
config.surveyID = 3160325;
/*config.animationMode = 0;*/
config.takeSurveyURL = 'http://www.surveyanalytics.com/a/TakeSurvey';
config.windowPositionLeft = 200;
config.windowPositionTop = 300;
config.home = 'http://www.surveyanalytics.com/';
config.isRightToLeft = false;
config.surveyStartMessage = 'Start Survey';
config.popupInvitationLaterMessage = 'Later';
config.showFooter = true;
config.invitationDelay = 0;
config.skipCount = 0;
config.popupMode = 0;
config.expirationTime = 60
window.onbeforeunload = function() {
QP_popupMain();
};
</script>
<script language="javascript" type="text/javascript" src="http://www.surveyanalytics.com//javascript/exitSurveyInvitation.js"></script>
<noscript>
<a href="http://www.supporterfeedback.org/a/TakeSurvey?id=3160325">Start Survey</a> <a href="http://www.surveyanalytics.com/">Survey</a>
</noscript>
这是function.php中的代码
add_action( 'wp_enqueue_scripts', 'register_my_script' );
function register_my_script() {
//This example puts it in plugins, but you can put it in your theme instead
wp_register_script( 'script', plugins_url( '/script.js/' , __FILE__ ), array(), '1.0.0', true );
}
//Replace "PUT YOUR JAVASCRIPT CODE IN HERE" with your actual code
function myTestFunction( $atts )
{
//Now enqueue the script
wp_enqueue_script( 'script' );
}
add_shortcode( 'myjavascriptfunction', 'myTestFunction' );