我有以下代碼獲取子IFRAME SRC值
我想獲得孩子的src值iframe.I我無法得到那個value.I甚至使用
document.getElementById("abcd")
also.But沒有運氣...
通過使用唯一的JavaScript我需要的解決方案。
在此先感謝...
我有以下代碼獲取子IFRAME SRC值
我想獲得孩子的src值iframe.I我無法得到那個value.I甚至使用
document.getElementById("abcd")
also.But沒有運氣...
通過使用唯一的JavaScript我需要的解決方案。
在此先感謝...
`src` is always the last URL that was loaded in the iframe without user interaction. I.e., it contains the first value for the URL, or the last value you set up with Javascript from the containing window doing:
document.getElementById("myiframe").src = 'http://www.google.com/';
如果用戶在iframe內的導航,你不能訪問使用src中的URL的值。在前面的例子,如果用戶在www.google.com上消失了,你做的事:
alert(document.getElementById("myiframe").src);
你仍然會得到「http://www.google.com」。
documentWindow.location.href
僅當iframe包含與包含窗口相同的域中的頁面時纔可用,但如果可用,它始終包含URL的正確值,即使用戶在iframe中導航。
如果您嘗試訪問(documentWindow
下或任何東西)documentWindow.location.href
和iframe是在不屬於包含窗口的域頁面時,它會拋出一個異常:
document.getElementById("myiframe").src = 'http://www.google.com/';
alert(document.getElementById("myiframe").documentWindow.location.href);
嘗試比較.src
和.documentWindow.location.href
的值爲iframe
。 (注意:documentWindow
在Chrome中被稱爲contentDocument
,因此Chrome中的.documentWindow.location.href
將代替.contentDocument.location.href
。)
您需要訪問相對於iFrame的DOM。看看http://stackoverflow.com/questions/1654017/how-to-expose-iframes-dom-using-jquery – 2014-09-29 12:16:45