2014-11-05 48 views
0

有点困惑。我正在尝试搜索iframe的内容并点击其中的链接。链接是'Attack'。找到最接近的tr ...脚本搜索祖先?

<script> 
setTimeout(function() { window.location.reload(); }, 1000); // 1 seconds, e.g. 

$(document).ready(function() { 
$('a[href*="5562089"]', $("game").contents()).closest('tr').find('.fightActionInnerInner').parent("a").trigger("clic k"); 
}); 
</script> 


<iframe src="http://vl.storm8.com/hitlist.php" width="100%" height="800px" id="game"></iframe> 

这里是我想与之交互的iframe中的HTML。

<td class="fightMobster"> 
    <div> 
     <a href="/profile.php?puid=5562089&formNonce=34947b8ffc73e8ceafabae71…94f&setTab1Badge=&h=2d55f5781bfe888b47d7f5c9dbc27df2f663347f"> 
      Lord Pookie 
     </a> 
    </div> 
    <div> 
     Lvl 212 Daywalker 
    </div> 
</td> 
<td class="fightSp"></td> 
<td class="fightMobSize"> 
    <span class="cash"> 
     <span style="white-space: nowrap;"> 
      <img width="15" height="14" style="padding-right:2px" src="http://static.storm8.com/zl/images/flesh.png?v=330"></img> 
      15,300 
     </span> 
    </span> 
</td> 
<td class="fightSpLg"></td> 
<td class="fightAction"> 
    <script> 
     function fsb99995143() { 
      var b=… 
    </script> 
    <a onclick="return fsb99995143();" href="/hitlist.php?tab=fight.php&action=fight&hitlistId=99995143&f…1b4b9390bee9a194f&h=284e4fe4946e6fb8af3a662f4583454eebc8bd23"> 
     <div class="fightActionInner"> 
      <div class="fightActionInnerInner"> 
       Attack 
      </div> 

我很困惑。脚本刷新页面,但似乎不想单击那里的链接。我究竟做错了什么?

+0

尝试更换“准备”与“载“in $(document).ready – 2014-11-05 11:46:33

+0

那么你有一个超时重新加载页面....看起来很奇怪。 – epascarello 2014-11-05 11:49:25

+0

@FrederikWitte感谢您的回复,但之后仍然没有变化我害怕:( – AdamH 2014-11-05 11:49:56

回答

0

下面一行是无用因此将其删除:

document.getElementById('game').contentWindow.document.body.innerHTML; 

首先,你不看在iframe的代码,您选择在当前窗口元素。所以你需要改变代码来查看iframe。

其次,contains selector看文本,而不是属性。你想使用attribute contains selector

变化

$('a:contains("5562089")') 

$('a[href*="5562089"]', $("game").contents()) 

,我不知道为什么你点击股利,而不是实际链接本身。

$('a[href*="5562089"]', $("game").contents()).closest('tr').find('.fightActionInnerInner').parent("a").trigger("click"); 

并希望iframe在您尝试点击它时完全加载。而如果函数的名称不会改变,你可以只调用函数下面的代码

$('#game')[0].contentWindow.fsb99995143(); 
+0

我改变了我的代码以匹配你的代码,但仍然没有变化,是因为它搜索页面而不是DOWN? – AdamH 2014-11-05 12:00:03

+0

最新更改后仍然没有变化:/ – AdamH 2014-11-05 12:16:41

+0

lol,y我们的代码没有看iframe中的代码... – epascarello 2014-11-05 12:32:42

0

尝试点击链接,如果链接包含的东西:

var th = $("a").attr("href"); 
var st = "5562089"; 
if(th.indexOf(st)!=-1){ 
    //Do your implementation 
}