2012-07-04 42 views
1

我想在加載link.php 4秒後爲框架1做一個自動點擊事件。我對Link.php代碼裏面skip.phpjquery和框架點擊事件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
</head> 
<body> 
<a href="http://www.example.com/"><img src="images/skip.png" border="0" alt="Skip"></a> 
</body> 
</html> 

當其內部skip.php粘貼的JavaScript代碼工作

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Source</title> 
<script type='text/javascript' src="js/jquery-1.5.2.min.js"></script> 
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){ 
$(function() { 
    $('[alt="Skip"]').click(function(){}); 
    setTimeout(function(){$('[alt="Skip"]').trigger('click');}, 4e3); 
}); 
});//]]> 
</script> 
</head> 
<frameset rows="200px,*" style="width:100%"> 
     <frame src="skip.php" frameborder="0" name="frame1" /> 
     <frame src="http://xyz.com" frameborder="0" /> 
</frameset><noframes></noframes> 
</body> 
</html> 

代碼,但我想工作它裏面link.php

+0

什麼是4E3在link.php設定的超時功能? – Polyov

+0

其4秒超時功能 – user1502071

+0

Inside skip.php alt =「skip」not alt =「跳過此廣告」 – user1502071

回答

2

工作腳本是

$(document).ready(function(){ 
$($('frame[name="frame1"]')[0].contentWindow).load(function() { 
var documentOfFrame = $('frame[name="frame1"]')[0].contentDocument; 

    $('[alt="Skip"]',documentOfFrame).click(function(){}); 
    setTimeout(function(){$('[alt="Skip"]',documentOfFrame).trigger('click');}, 4e3); 
}); 
}); 
0

您需要指定框架的文件作爲背景爲jQuery()選擇:

$(function() { 
    //Waiting till the frame's hierarchy will be constructed 
    $(frames['frame1']).load(function() { 
     var documentOfFrame = this.contentDocument; 

     $('[alt="Skip"]',documentOfFrame).click(function(){}); 
     setTimeout(function(){$('[alt="Skip"]',documentOfFrame).trigger('click');}, 4e3); 
    }); 
}); 

請參閱"Selector Context"部分。

+0

這一個也不起作用 – user1502071

+0

@ user1502071嘗試這些'$(document).ready(function(){$ ($('frame [name =「frame1」]')[0] .contentWindow).load(function(){alert('frame is loaded');});});''和$(window)。 load(function(){alert('main content is loaded');});'。然後告訴我警報觸發的順序。 – Engineer

+0

加載了一個警告幀 – user1502071