2012-10-19 3 views
3

나는 HTML 헤더에 배치됩니다 시각적 웹 사이트 최적화에서 자바 스크립트 코드가 있습니다JQuery와 시각적 인 웹 사이트 최적화 코드

var _vwo_code=(function(){ 
var account_id=7237, 
settings_tolerance=2000, 
library_tolerance=1500, 
use_existing_jquery=true, 
// DO NOT EDIT BELOW THIS LINE 
f=false,d=document;return{use_existing_jquery:function(){return use_existing_jquery;},library_tolerance:function(){return library_tolerance;},finish:function(){if(!f){f=true;var a=d.getElementById('_vis_opt_path_hides');if(a)a.parentNode.removeChild(a);}},finished:function(){return f;},load:function(a){var b=d.createElement('script');b.src=a;b.type='text/javascript';b.innerText;b.onerror=function(){_vwo_code.finish();};d.getElementsByTagName('head')[0].appendChild(b);},init:function(){settings_timer=setTimeout('_vwo_code.finish()',settings_tolerance);this.load('//dev.visualwebsiteoptimizer.com/j.php?a='+account_id+'&u='+encodeURIComponent(d.URL)+'&r='+Math.random());var a=d.createElement('style'),b='body{opacity:0 !important;filter:alpha(opacity=0) !important;background:none !important;}',h=d.getElementsByTagName('head')[0];a.setAttribute('id','_vis_opt_path_hides');a.setAttribute('type','text/css');if(a.styleSheet)a.styleSheet.cssText=b;else a.appendChild(d.createTextNode(b));h.appendChild(a);return settings_timer;}};}());_vwo_settings_timer=_vwo_code.init(); 

을하지만, 나는 단지이 조건이 코드를 실행하려면 :

$(document).ready(function(){ 
    if($('#selectedLang').val() == 'en_US') 
    { 
    //run the visual website optimizer code 
    } 
}); 

나는이 시도했지만 오류

$(document).ready(function(){ 
    if($('#selectedLang').val() == 'en_US') 
    { 
    var _vwo_code=(function(){ 
    var account_id=7237, 
    settings_tolerance=2000, 
    library_tolerance=1500, 
    use_existing_jquery=true, 
    // DO NOT EDIT BELOW THIS LINE 
    f=false,d=document;return{use_existing_jquery:function(){return use_existing_jquery;},library_tolerance:function(){return library_tolerance;},finish:function(){if(!f){f=true;var a=d.getElementById('_vis_opt_path_hides');if(a)a.parentNode.removeChild(a);}},finished:function(){return f;},load:function(a){var b=d.createElement('script');b.src=a;b.type='text/javascript';b.innerText;b.onerror=function(){_vwo_code.finish();};d.getElementsByTagName('head')[0].appendChild(b);},init:function(){settings_timer=setTimeout('_vwo_code.finish()',settings_tolerance);this.load('//dev.visualwebsiteoptimizer.com/j.php?a='+account_id+'&u='+encodeURIComponent(d.URL)+'&r='+Math.random());var a=d.createElement('style'),b='body{opacity:0 !important;filter:alpha(opacity=0) !important;background:none !important;}',h=d.getElementsByTagName('head')[0];a.setAttribute('id','_vis_opt_path_hides');a.setAttribute('type','text/css');if(a.styleSheet)a.styleSheet.cssText=b;else a.appendChild(d.createTextNode(b));h.appendChild(a);return settings_timer;}};}());_vwo_settings_timer=_vwo_code.init(); 
    } 
}); 

내가 어떻게 해결할 수에 제발 도와주세요 "_vwo_code가 정의되어 있지 않습니다"를 반환 이? 미리 감사드립니다!

답변

6

VWO에서 필요한 것은 _vwo_code 변수를 전역 적으로 사용할 수 있지만 문서 준비 처리기 내에서 변수를 정의 할 때 로컬 범위에 남아 있으므로 외부에서 액세스 할 수 없습니다. 그래서

는 대신

var _vwo_code=(function(){ 

window._vwo_code=(function(){ 

쓰기 그러나 문서가 준비 후 지금 VWO 코드, 당신은 플리커 (원본 콘텐츠가 표시 볼 수 있습니다 실행되는 여기 기억할 수있는이 문제를 해결하려면 변경 사항이 적용되기 전에) 테스트 페이지에 표시됩니다.

(주의 : 나는 VWO에서 일한다)

+0

그것은 작동한다! 감사! :) – scoohh

+0

방금이 오류를 발견했습니다. 어떻게 해결할 수 있습니까? 'vwo _ $. parseJSON이 함수가 아닙니다' – scoohh

+0

당신의 변형 변화 어딘가에'vwo _ $. parseJSON'을 사용하고 있습니까? –

관련 문제