0

How to access the variable which is inside the script tag (Script considered as string).

I will get this content with this content i have to access this varible ad_json

console.log(document.querySelectorAll('iframe')[0].contentDocument.querySelectorAll('script')[1].outerHTML)

It will output the String

<script type="text/javascript">
        function populate(el) { var adBlock = document.getElementById("adBlock");adBlock.innerHTML += el;}
        var caps_ = {
"clicktracking": true, "customAdIcons": true, "isLtr": true, "isRtl": false, "isDesktop": true
};
        var IS_GOOGLE_AFS_IFRAME_ = true;
        var ad_json = {
          "ads": [],
          "ias": [],
          "rss": [{
            "t": "Crossover Vehicles",
            "tr": {
              "c": "Crossover Vehicles",
              "rtl": false
            },
            "afdt": "CpECChMIyPq38qfP1QIVUIpoCh3YFwx5GAEgAFDtrdAJULSu0AlQsa_QCVC4r9AJUMqv0AlQjrDQCVCesNAJUKew0AlQqLDQCVCpsNAJULKw0AlQtLDQCVC1sNAJULew0AlQuLDQCVC7sNAJUL2w0AlQwrDQCVDDsNAJUMSw0AlQxrDQCVDKsNAJUM2w0AlQ0bDQCVDTsNAJUNew0AlQ6qjRClDrzMcMUO-c5RFQ6LyoE1D70MEsUPv9yTVQ95D4OVD1su6XAVCoq_SxAVC2ycWzAVCm87COAlChxbHZAlDR1cD7AnFzram4RtNPKYIBEwihm7jyp8_VAhWKpGgKHU84BAaNAafQqOyRASXTH-N91-AHEhkAbTqKkE4-VScYvnqlFNlUs05lIpYTIMy7",
            "fn": "slave-0",
            "sls": []},{
            "t": "Crossover SUV",
            "tr": {
              "c": "Crossover SUV",
              "rtl": false
            },
            "afdt": "CpECChMIyPq38qfP1QIVUIpoCh3YFwx5GAEgAVDtrdAJULSu0AlQsa_QCVC4r9AJUMqv0AlQjrDQCVCesNAJUKew0AlQqLDQCVCpsNAJULKw0AlQtLDQCVC1sNAJULew0AlQuLDQCVC7sNAJUL2w0AlQwrDQCVDDsNAJUMSw0AlQxrDQCVDKsNAJUM2w0AlQ0bDQCVDTsNAJUNew0AlQ6qjRClDrzMcMUO-c5RFQ6LyoE1D70MEsUPv9yTVQ95D4OVD1su6XAVCoq_SxAVC2ycWzAVCm87COAlChxbHZAlDR1cD7AnFzram4RtNPKYIBEwihm7jyp8_VAhWKpGgKHU84BAaNAUwFWeiRASXTH-N91-AHEhkAbTqKkLA6p3f0s6oWGbqSRGWBz9IMpH3w",
            "fn": "slave-0",
            "sls": []},{
            "t": "Cross over Vehicle",
            "tr": {
              "c": "Cross over Vehicle",
              "rtl": false
            },
            "afdt": "CpECChMIyPq38qfP1QIVUIpoCh3YFwx5GAEgAlDtrdAJULSu0AlQsa_QCVC4r9AJUMqv0AlQjrDQCVCesNAJUKew0AlQqLDQCVCpsNAJULKw0AlQtLDQCVC1sNAJULew0AlQuLDQCVC7sNAJUL2w0AlQwrDQCVDDsNAJUMSw0AlQxrDQCVDKsNAJUM2w0AlQ0bDQCVDTsNAJUNew0AlQ6qjRClDrzMcMUO-c5RFQ6LyoE1D70MEsUPv9yTVQ95D4OVD1su6XAVCoq_SxAVC2ycWzAVCm87COAlChxbHZAlDR1cD7AnFzram4RtNPKYIBEwihm7jyp8_VAhWKpGgKHU84BAaNAV29F-WRASXTH-N91-AHEhkAbTqKkENkB4HSdl0GsagRpK2rY8hGuQWV",
            "fn": "slave-0",
            "sls": []},{
            "t": "Best Crossover",
            "tr": {
              "c": "Best Crossover",
              "rtl": false
            },
            "afdt": "CpECChMIyPq38qfP1QIVUIpoCh3YFwx5GAEgA1DtrdAJULSu0AlQsa_QCVC4r9AJUMqv0AlQjrDQCVCesNAJUKew0AlQqLDQCVCpsNAJULKw0AlQtLDQCVC1sNAJULew0AlQuLDQCVC7sNAJUL2w0AlQwrDQCVDDsNAJUMSw0AlQxrDQCVDKsNAJUM2w0AlQ0bDQCVDTsNAJUNew0AlQ6qjRClDrzMcMUO-c5RFQ6LyoE1D70MEsUPv9yTVQ95D4OVD1su6XAVCoq_SxAVC2ycWzAVCm87COAlChxbHZAlDR1cD7AnFzram4RtNPKYIBEwihm7jyp8_VAhWKpGgKHU84BAaNAYmlWm-RASXTH-N91-AHEhkAbTqKkA2DzXXg5M1ahVaNg45HmdPJouvl",
            "fn": "slave-0",
            "sls": []},{
            "t": "AWD Crossovers",
            "tr": {
              "c": "AWD Crossovers",
              "rtl": false
            },
            "afdt": "CpECChMIyPq38qfP1QIVUIpoCh3YFwx5GAEgBFDtrdAJULSu0AlQsa_QCVC4r9AJUMqv0AlQjrDQCVCesNAJUKew0AlQqLDQCVCpsNAJULKw0AlQtLDQCVC1sNAJULew0AlQuLDQCVC7sNAJUL2w0AlQwrDQCVDDsNAJUMSw0AlQxrDQCVDKsNAJUM2w0AlQ0bDQCVDTsNAJUNew0AlQ6qjRClDrzMcMUO-c5RFQ6LyoE1D70MEsUPv9yTVQ95D4OVD1su6XAVCoq_SxAVC2ycWzAVCm87COAlChxbHZAlDR1cD7AnFzram4RtNPKYIBEwihm7jyp8_VAhWKpGgKHU84BAaNAWyi6KORASXTH-N91-AHEhkAbTqKkEcjuf9cx8bN0AZVTs0PNCVoIyxQ",
            "fn": "slave-0",
            "sls": []},{
            "t": "Compare Luxury Cars",
            "tr": {
              "c": "Compare Luxury Cars",
              "rtl": false
            },
            "afdt": "CpECChMIyPq38qfP1QIVUIpoCh3YFwx5GAEgBVDtrdAJULSu0AlQsa_QCVC4r9AJUMqv0AlQjrDQCVCesNAJUKew0AlQqLDQCVCpsNAJULKw0AlQtLDQCVC1sNAJULew0AlQuLDQCVC7sNAJUL2w0AlQwrDQCVDDsNAJUMSw0AlQxrDQCVDKsNAJUM2w0AlQ0bDQCVDTsNAJUNew0AlQ6qjRClDrzMcMUO-c5RFQ6LyoE1D70MEsUPv9yTVQ95D4OVD1su6XAVCoq_SxAVC2ycWzAVCm87COAlChxbHZAlDR1cD7AnFzram4RtNPKYIBEwihm7jyp8_VAhWKpGgKHU84BAaNAWMpD6CRASXTH-N91-AHEhkAbTqKkCRn1yPsJQ5Y7wZcHmxdz3jorS0w",
            "fn": "slave-0",
            "sls": []},{
            "t": "Mid Size Luxury Cars",
            "tr": {
              "c": "Mid Size Luxury Cars",
              "rtl": false
            },
            "afdt": "CpECChMIyPq38qfP1QIVUIpoCh3YFwx5GAEgBlDtrdAJULSu0AlQsa_QCVC4r9AJUMqv0AlQjrDQCVCesNAJUKew0AlQqLDQCVCpsNAJULKw0AlQtLDQCVC1sNAJULew0AlQuLDQCVC7sNAJUL2w0AlQwrDQCVDDsNAJUMSw0AlQxrDQCVDKsNAJUM2w0AlQ0bDQCVDTsNAJUNew0AlQ6qjRClDrzMcMUO-c5RFQ6LyoE1D70MEsUPv9yTVQ95D4OVD1su6XAVCoq_SxAVC2ycWzAVCm87COAlChxbHZAlDR1cD7AnFzram4RtNPKYIBEwihm7jyp8_VAhWKpGgKHU84BAaNAZZA-FCRASXTH-N91-AHEhkAbTqKkJMEmTodIn7fE9H36fnSp-Q5BPbZ",
            "fn": "slave-0",
            "sls": []},{
            "t": "Top 10 Best Cars",
            "tr": {
              "c": "Top 10 Best Cars",
              "rtl": false
            },
            "afdt": "CpECChMIyPq38qfP1QIVUIpoCh3YFwx5GAEgB1DtrdAJULSu0AlQsa_QCVC4r9AJUMqv0AlQjrDQCVCesNAJUKew0AlQqLDQCVCpsNAJULKw0AlQtLDQCVC1sNAJULew0AlQuLDQCVC7sNAJUL2w0AlQwrDQCVDDsNAJUMSw0AlQxrDQCVDKsNAJUM2w0AlQ0bDQCVDTsNAJUNew0AlQ6qjRClDrzMcMUO-c5RFQ6LyoE1D70MEsUPv9yTVQ95D4OVD1su6XAVCoq_SxAVC2ycWzAVCm87COAlChxbHZAlDR1cD7AnFzram4RtNPKYIBEwihm7jyp8_VAhWKpGgKHU84BAaNAX8d3WGRASXTH-N91-AHEhkAbTqKkBDenlZUpnknf5QoiNQMdwbtFUIt",
            "fn": "slave-0",
            "sls": []}],
          "sbs": [],
          "attr":{"t":"Sponsored Listings","u":"https://www.google.com/adsense/support/bin/request.py?contact=abg_afc&url=http://crossovercarstoday.sale/&hl=en&client=dp-dotzup20_3ph_js&gl=IN",
            "alt_t":{
              "Ads":"Ads",
              "Sponsored Listings":"Sponsored Listings"
            }
          },
          "rs_attr":{"t":"Related Links","u":"https://www.google.com/adsense/support/bin/request.py?contact=abg_afc&url=http://crossovercarstoday.sale/&hl=en&client=dp-dotzup20_3ph_js&gl=IN"}
        };
        var status_ = {
          "feed": "afc"
        };
      </script>

I don't how to parse this as a javascript content and get the varible

Nane
  • 2,370
  • 6
  • 34
  • 74
  • 1
    This is in an iframe? Is the domain of the iframe the same as the outer page? If they're different domains, you may not be able to access its contents. – Harris Aug 11 '17 at 14:13
  • i've disabled the web security for developent – Nane Aug 11 '17 at 14:14
  • 1
    You may want to check out [this question and answer](https://stackoverflow.com/questions/13757943/access-a-variable-of-iframe-from-parent). – Harris Aug 11 '17 at 14:14
  • @HarrisWeinstein it is not working for me – Nane Aug 11 '17 at 14:26
  • What errors or output are you getting? Can you show all relevant HTML and code? – Harris Aug 11 '17 at 14:50

0 Answers0