2016-08-22 12 views
-2

まあ、これは私が値を取得するために、アレイthorugh反復処理したい、私のために少し混乱して、私はしていないどのようにそれを説明するために:私は(XXXXXをccs_cc_loge_xxxxxxする取得したいjs変数配列を反復するには?

ccs_cc_args = 

ccs_cc_logsvc = function ccs_cc_logsvc(){var t=this;t.pStart="ccs_cc_log_startTime",t.pInit="ccs_cc_initParams",t.pId=t.genGuid(),"undefined"==typeof window[t.pStart]&&(window[t.pStart]=(new Date).getTime()),t.ping=function(){t.pingCount++,t.pingCount>1&&t.sendEvent("Ping"),t.pingCount<=t.maxPing&&window.setTimeout(t.ping,t.pingPeriod)};try{t.host=window.location.href.substr(0,300)}catch(e){}t.cnt=0,t.init(),t.sendEvent("TInit",null,!0),t.setPing(0,15e3)} 
ccs_cc_contentloader = function ccs_cc_contentloader(t){var e=this,c="ccs_loading_scripts";"undefined"==typeof window[c]&&(window[c]=[]),e.isLoading=!1,e.addedObjects=[],e.waitLoadScripts=[],e.cssToLoad=0,e.scriptToLoad=0,e.objName=t,e.addedRefs=[],e.loadingCSS=[],e.isLoadFinishing=!1,e.objectToLoad=null,e.contextId=null,e.lastScript=null,e.lastTarget=null,e.navigated=!0,e.defaultUrl={},e.loadingScripts=window[c],e.ccsHost=ccs_cc_log.ccsHost,e.skey=ccs_cc_log.skey,window.setInterval(function(t){return function(){t.navTo()}}(this),50)} 

ccs_cc_log = [object Object] 
ccs_cc_initParams = ,ws.pagecontent.com 

ccs_cc_log_startTime = 1471905959132 

ccs_cc_debug_lastUrl = http://ws.pagecontent.com/7f08cde9/script/hp-auto-pp?cpn=CPN&mf=HP&pn=T1C06…ean=UPC_EAN_CODE&lang=ES&market=MX&host=&nld=1 

ccs_cc_loadQueue = 

ccs_loading_scripts = 
ccs_cc_ld_hp-auto-pp = [object Object] 
ccs_cc_loge_aa0e4d = function ccs_cc_loge_aa0e4d(id, clientParams, args){var et; var serverParams;switch (id) { 
case '5901d207': et='ProductHookLoad'; serverParams={"ServerTime":"1","ResultCode":"100"}; break; 
} ccs_cc_log.logEvent (et, 'SKey=abcd74589&LCID=2415&Market=MX&Locale=ES-MEX&ZoneId=hp-auto-pp&ZoneVer=1&SMfgName=HP&SMfgPn=TOM025HAC6547&MfgId=23', serverParams, clientParams); } 

されるので、それは毎回ページのリロードを変更する)ので、この内部で、私はResultcodeとその応答を読み込み/取得したい。

私はこのようなすべてのグローバルを読み込もうとしましたので、私はすべてのデータを読み取ることができます:

<script> 

$(document).ready(function() { 
    (function() { 
var iframe = document.createElement('iframe'); 
iframe.onload = function() { 
    var iframeKeys = Object.keys(iframe.contentWindow); 
    Object.keys(window).forEach(function(key) { 
    if(!(key in iframeKeys)) { 
     console.log(key+" = "+window[key]); 

    } 
    }); 
}; 
iframe.src = 'about:blank'; 
document.body.appendChild(iframe); 
})(); 
}); 
</script> 

これを達成するための任意の方法を?

+2

コードのイメージは、おそらく多くの答えを得ることはできません。質問/ –

+0

のテキスト/コードとして良いでしょう。 、私は最後にイメージを置くだろう。 –

+1

恐ろしい書式設定。 – PHPglue

答えて

1

最初は非常に恐ろしいアイデアにハックされていますが、必要な変数名パターンと一致するキーだけをループすることでこれを行うことができます。

のでループし、プリントキーコードで、次の操作を行います。XXXXは数字の任意の量である場合

if(/^ccs_cc_loge_[0-9]+$/.test(key)) { 
    // call code that needs to use this variable; 
}; 

この正規表現はccs_cc_loge_Xを持つ任意の変数の開始と一致します。これはより具体的で、ブラウザと互換性があり、.startsWithのような文字列関数を使用します。

+0

右のトラックの右に、ありがとう&はい私はこれが恐ろしい考えであることを知っているが、それは私のものではなかった – Rhopercy

関連する問題