2010-12-10 93 views
-3

我如何從iframe中提取所有文本?如何獲取iframe的內容?

有沒有辦法做到這一點?

+1

上的代理是您的域的此iframe一部分,因爲如果它不是,你就違反了[相同來源政策](http://en.wikipedia.org/wiki/Same_origin_policy)? – 2010-12-10 16:00:32

+2

你已經標記了這個PHP和JavaScript。你是在談論在JS中用瀏覽器做這件事,還是用PHP解析文檔,在其中找到iframe,然後解析引用的文檔? – Quentin 2010-12-10 16:01:13

+0

這味道不好... – Trufa 2010-12-10 16:09:10

回答

2

客戶方的域相同:

var doc; 
if (document.getElementById(iframeId).contentDocument) { // newer browsers 
    doc = document.getElementById(iframeId).contentDocument; 
} 
else if (document.getElementById(iframeId).contentWindow) { // older IE 
    doc = document.getElementById(iframeId).contentWindow.document 
} 
if (doc) { alert(doc.body.innerHTML) } 

如果沒有,您需要爲Windows的HTA或服務器