在我的页面上有一个“继续”按钮,当用户单击该按钮时,我调用一个验证函数,如果页面上有任何错误,我会将它们显示在顶部,然后用window.scrollTo(0,0);滚动给它们。
现在,这个页面被加载到一个iframe中,并且window.scrollTo(0,0);无法工作。我尝试了所有可能的方法,如window.parent.scrollTo(0,0);或$('#error_msg_smry').animate({ scrollTop: 0 }, 0);,但都没有用。
下面是我的代码(下面是错误消息div ):
<div id="error_msg_smry" class="error_msg_summary" style="display:none;" >
<br/>
<div class="error_msg_heading">Sorry, but we cannot process your donation until the following errors have been fixed:</div>
<div> </div>
<div class="error_messages">
<div id="selDonationErr" class="textClass" style="color:#b94a48; font-weight:400;"></div>
<div id="otherAmtErr" class="textClass" style="color:#b94a48; font-weight:400;"></div>
<div id="lessDonationErr" class="textClass" style="color:#b94a48; font-weight:400;"></div>
<div id="recipientErr" class="textClass" style="color:#b94a48; font-weight:400;"></div>
<div id="firstNameErr" class="textClass" style="color:#b94a48; font-weight:400;"></div>
<div id="lastNameErr" class="textClass" style="color:#b94a48; font-weight:400;"></div>
<div id="emailErr" class="textClass" style="color:#b94a48; font-weight:400;"></div>
<div id="creditCardNameErr" class="textClass" style="color:#b94a48; font-weight:400;"></div>
<div id="creditCardNumberErr" class="textClass" style="color:#b94a48; font-weight:400;"></div>
<div id="creditCardExpiryMonthErr" class="textClass" style="color:#b94a48; font-weight:400;"></div>
<div id="creditCardExpiryYearErr" class="textClass" style="color:#b94a48; font-weight:400;"></div>
<div id="creditCardCCVErr" class="textClass" style="color:#b94a48; font-weight:400;"></div>
</div>
<br/>
</div>下面的按钮:
<apex:commandButton styleclass="btn" action="{!makeDonation}" onClick="return validate();" value="Continue"/> 在我的验证函数中,我执行以下操作:
if(isPass == false){
document.getElementById("error_msg_smry").style.display = 'block';
window.scrollTo(0,0);
}我无法访问父页面(在我的iframe之外)。
有人能帮帮我吗?
发布于 2018-01-22 12:22:13
如果有人面临同样的问题并寻求解决方案,我的回答是:
我在下面的代码中解析了它:
if(isPass == false){
document.getElementById("error_msg_smry").style.display = 'block';
// window.scrollTo(0,0);
var div = document.createElement("div");
div.innerHTML = "<a style='position:absolute;left:0;top:0px' href='#'></a>";
div = div.firstChild;
document.body.appendChild(div);
div.focus();
div.parentNode.removeChild(div);
}
else{
document.getElementById("error_msg_smry").style.display = 'none';
}
return isPass;
}https://stackoverflow.com/questions/45954261
复制相似问题