2013-06-19 44 views
0

我需要更改點擊時iframe的高度。 IFrame,這是與此代碼創建:如果點擊iframe高度變化

var box = document.createElement('iframe'); 
box.id = "statasa"; 
box.setAttribute('onclick', 'getmap()'); 
box.src = 'http://www.mysite.com/map.php'; 
box.frameBorder = 1; 
box.style.border = 1; 
box.style.overflow = 'hidden'; 
box.style.cursor = 'pointer'; 
box.style.width = '300px'; 
box.style.height = '720px'; 
box.style.position = 'absolute'; 
document.getElementsByTagName('body')[0].appendChild(box); 

這是函數:

function getmap() { 
    d = document.getElementById('statasa'); 
    d.style.width="150px"; 
    d.style.height="150px"; 
} 

哪裏錯誤?有更簡單的方法嗎?

+0

您不能單擊「IFRAME」,減少它的寬度和高度,因爲......它會影響其子元素。 – Rajiv007

回答

0

您無法檢測到iframe中的點擊事件。請參閱Detect Click into Iframe using JavaScript


至於問題的第二部分,以簡化的方式是不是:

box.setAttribute('onclick', 'getmap()'); 

使用:

box.onclick = getmap(); 
+0

正在工作,但只有當我點擊iframe邊框 – Barricade