1

即時編寫一個litell表單填充爲Chrome Extenstion,其中1個文本字段爲iframe。javascript chrome擴展:向iframe添加元素或字符串

即時嘗試添加一些字符串的iframe身體標籤。

這是怎樣的網站Iframe HTML代碼的樣子,afther頁面加載(從鉻devlopers工具F12了它):

<iframe frameborder="0" id="wysiwygtextfield" style="height: 100px; width: 600px; "> 
#document 
<html> 
    <head> </head> 
    <body> 
    <br/> 
    </body> 
</html> 
</iframe> 

現在我Content Script嘗試一些字符串添加到身體:

if ($("#wysiwygtextfield").contents().find("body").length > 0) { 
    var body = $("#wysiwygtextfield").contents().find("body").val("some msg"); 
} 

我嘗試了沒有使用jquery的模擬代碼,但它仍然沒有工作。我想知道Same origin policy,但我不確定它適用於此。因爲,腳本在客戶端運行。 (或mybee我錯了)。

有什麼我可以做的嗎?

(抱歉,我的英語)

+1

'val'用於獲取/設置表單元素的值,對於body元素,您應該使用'html'方法。 – undefined

+0

將評論留下回復我想要接受我愛你! – samy

回答

1

val用於獲取/設置形式的元素的值,對於體元件應該使用html方法來代替。

$("#wysiwygtextfield").contents().find("body").html("some msg") 
+0

非常感謝你!我不敢相信這很簡單。只需要等待6分鐘就可以接受。 – samy

+0

@samy歡迎您:) – undefined