拦截框架中的链接点击
我有一个旧式页面,它使用包含顶部框架和底部框架的框架集。框架集在“index.html”中定义,我的代码如下:
<html>
<head>
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
$('#mainFrame').ready(function() {
$('#mainFrame a').live('click', function() {
alert('u click');
return false;
});
});
});
</script>
</head>
<frameset id="main" rows="125,*" cols="*">
<frame src="header.html" name="headerFrame" id="headerFrame" />
<frame src="main.html" name="mainFrame" id="mainFrame" />
</frameset>
</html>
我希望能够拦截在框架“mainFrame”上单击的链接。我以为我可以为其添加一个就绪事件,然后实时绑定单击事件,但它不起作用。有什么想法吗?
注意:这些文件都位于同一域中,因此这不是 XSS 问题。
I have a old fashion page that uses a frameset containing a top frame and bottom frame. The frameset is defined in "index.html" and my code is as follows:
<html>
<head>
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
$('#mainFrame').ready(function() {
$('#mainFrame a').live('click', function() {
alert('u click');
return false;
});
});
});
</script>
</head>
<frameset id="main" rows="125,*" cols="*">
<frame src="header.html" name="headerFrame" id="headerFrame" />
<frame src="main.html" name="mainFrame" id="mainFrame" />
</frameset>
</html>
I would like to be able to intercept links that are clicked on the frame "mainFrame". I thought I could just add a ready event for it then live bind click events but it doesn't work. Any ideas?
Note: The files are all on the same domain so this is not an XSS issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需要向 jQuery 语句添加一个上下文,告诉它在哪里查找 #mainFrame a
哦,是的......您肯定需要确保 iframe 已加载。 “live”应该解决这个问题......但我现在正在做一些事情,我必须为 jQuery 编写一个自定义的 ready() 插件,以确保我的框架已加载,因为我在使用 Chrome 时遇到了问题。
Chrome 和 IE 似乎用 document.addEventListener("DOMContentLoaded"... 来抢先一步...我相信这就是 jQuery 中的 read() 函数所使用的。
无论如何,只要确保你的 iframe 完全加载即可。
You just need to add a context to jQuery statement, to tell it where to look for #mainFrame a
Oh yeah....you definitely need to make sure that the iframe is loaded. The "live" should take care of that...but I'm working on something now where I had to write a custom ready() plugin for jQuery to make sure my frames were loaded, because I was having trouble with Chrome.
Chrome and IE seem to jump the gun on with the document.addEventListener("DOMContentLoaded"... which I believe is what the ready() functions in jQuery use.
Anyways, just make sure that your iframes get loaded all the way.