2013-11-21 83 views
1

如果您加載vBulletin(3.6.8)js feed例如http://www.example.com/forum/external.php?type=js你會得到的輸出是這樣的:爲什麼vBulletin在其js feed中返回一個函數?

function thread(threadid, title, poster, threaddate, threadtime) { 
    this.threadid = threadid; 
    this.title = title; 
    this.poster = poster; 
    this.threaddate = threaddate; 
    this.threadtime = threadtime; 
} 

var threads = new Array(15); threads[0] = new thread(370145, ...rest of threads in an array...); 

有什麼用這個函數對象,什麼將評估從JavaScript(Node.js的)這個JS,因爲的eval()是潛在的不安全一種安全的方式。

var phantom = require('phantom'); 
phantom.create(function(ph) { 
    return ph.createPage(function(page) { 
     return page.open("http://www.example.com/forum/external.php?type=js&forumids=1&lastpost=1", function(status) { 
      console.log("opened page? ", status); 
      return page.get('plainText', function(content){ 
       console.log(content); 
       eval(content); //danger! 
       console.log(thread); 

       return ph.exit(); 
      }); 
     }); 
    }); 
}); 

回答

1

您可以在外部加載script標記,然後訪問threads陣列。

<script src="/path/to/external.php"></script> 
<script> 
    threads.forEach(function(thread) { 
     //do something with thread, has the objects listed in thread() 
    } 
</script> 
+0

謝謝 - 我應該提到我在Node.js中做的不是瀏覽器。 – codecowboy

+0

然後我會使用XML Syndication。 – Gant

相關問題