2013-10-07 13 views
0

我試圖禁用/啓用超鏈接的頁面上可能發生的幾個點擊事件,正在加載[iframe name =「 homeFrame「],事件可以是按鈕點擊。啓用/禁用從iFrame中的父元素的HTML超鏈接(對於給定的結構)使用jquery/javascript

div leftNav包含導航鏈接,它會在[iframe name =「homeFrame」]中加載。

我想知道,如何禁用/啓用從Iframe中加載頁面的鏈接。

請指導我一樣!謝謝!

HTML代碼:

<html> 
<body> 
<form name="frmHome"> 

<div id="MainDivH" style="background-image:url(images/headerbg.jpg); background-repeat:repeat-x; width:100%;"> 
    <div id="header" style="width:984px; font-family:Calibri; padding-left: 37px;"> 
    </div> 

    <div id="divNavigation" class="divNavigation" style="padding-left:37px; float:left;"> 

    <div id="countrydivcontainer" style="float:left" > 
    <div id="divProduct" style="padding-bottom:20px; padding-top:20px; position:static;"> 

    </div> 

    <div id="PCcontentWrapper"> 
     <div class="leftNav" style="font-size:14px; font-weight:normal;"> 
      <ul id="topUL"> 
      <div background:url(images/pcnav.png) left top no-repeat;">TEST LINKS</div> 
      <li style="text-align:center;"><a id="202" name="test1" class="test" href="javascript:void(0);" onclick="javascript:top.frames['homeFrame'].location='TestLink/link1.php'" target="homeFrame">&nbsp;Test 1</a></li> 
      <li style="text-align:center;"><a id="204" name="test2" class="test" href="javascript:void(0);" onclick="javascript:top.frames['homeFrame'].location='TestLink/test2.php'" target="homeFrame">&nbsp;Test 2</a></li> 
      </ul> 
     </div> 
    <!--End of left nav--> 

    <div class="pcContener" id="pcContener" style="float:right; padding-left:20px;"> 
     <iframe name="homeFrame" id="homeFrame" scrolling="no" style="height:750px; float:right; width:758px; font:Calibri; overflow:hidden;"> 


     </iframe> 
    </div> 

    </div> 
</div> <!--End of PCcontentWrapper--> 
</div> <!--End of divNavigation-->  
</div> <!--End of MainDivH--> 
</form> 
</body> 
+0

這聽起來像一個XY-問題 - http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem - 請介紹一下X! – Halcyon

+0

你想要在你的iframe頁面禁用你的父頁面的鏈接? – Abhidev

+0

@Abhidev:是的,我正在嘗試同樣的事情。 – Emma

回答

1

你可以做的就是在你的父頁一個js功能將禁用的鏈接。

父頁面JS ...更新

function disableLinks(){ 
    var links = $('#topUL a'); 
    links.each(function(){ 
     $(this).click(function(){ 
      return false; 
     }); 
    }); 
} 

調用父js函數在自己的iframe

的iframe頁面JS

window.parent.disableLinks(); 
+0

謝謝!函數被調用,但鏈接仍然可點擊! – Emma

+0

你可以檢查鏈接變量的值.... – Abhidev

+0

它返回[對象對象] – Emma

1
if(condition)//write ur conditions here 
     disableLink(); 
    else 
     showLink(); 



    function disableLink() 
      { 

      document.getElementById('Link1').disabled=true; 
      document.getElementById('Link1').removeAttribute('href');  
      document.getElementById('Link1').style.textDecoration = 'none'; 
      document.getElementById('Link1').style.cursor = 'default'; 
      } 

    function showLink() 
      { 
      document.getElementById('Link1').disabled=false; 
      document.getElementById('Link1').href = "somepage.html"; 
      document.getElementById("Link1").style.textDecoration = "underline"; 
      document.getElementById("Link1").style.cursor = "hand"; 
      } 
相關問題