jQuery iframe 选择源 DOM 元素
我需要创建一个带有 iframe 的 jQuery 对话框,该 iframe 指向同一域下的页面。我只想要该页面的特定 ID,而不是整个页面。我无法使用 .load() 因为源页面上有链接,如果有人单击它们,则带有对话框的页面会刷新,而我无法使用它。我希望有办法解决这个问题。这是我尝试过的:
$('<iframe src="'+frameurl+'" id="dialogframe" frameBorder="0" />').contents().find("#idthatiwant").dialog({attributes});
I need to create a jQuery dialog with an iframe that points to a page under the same domain. I just want a specific ID of that page, not the whole thing. I can't use .load() because there are links on the source page and if someone clicks on them then the page with the dialog box refreshes and I can't have that. I hope there's a way around this. This is what I tried:
$('<iframe src="'+frameurl+'" id="dialogframe" frameBorder="0" />').contents().find("#idthatiwant").dialog({attributes});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

这可能不完全是您正在寻找的,如果不是,我表示歉意,但当我处于同样的紧要关头时,它对我有用。
这个想法是设置一个div的href,普通的ajax,但是重写点击和提交事件以使用ajax。因此,其工作方式与 iframe 非常相似,但实际上并不是 iframe。
我有一个名为 externalContainer 的 div,这是 js:
然后我只需调用
$('#externalContainer').load("file.php");
来加载新的 html。不具备普通 iframe 的所有“功能”,但可能能够满足您的需要。
应该指出的是,我在 stackoverflow 上的另一个问题上发现了我相信的这种技术:)。
编辑:
应该注意的是,这也允许来自“iframe”内的 ajax 内容,这就是为什么我验证 href 不等于“#”。如果您计划使用表单提交内容,这也取决于 ajaxForm jquery 插件。
This may not be exactly what you're looking for, and if not, I appologize, but it worked for me when I was under the same crunch.
The idea is to set the href of a div, normal ajax, but to override click and submit events to use ajax instead. Thus working much like an iframe, but not actually being an iframe.
I had a div named externalContainer, and here's the js:
I would then simply call
$('#externalContainer').load("file.php");
to load the new html in.This doesn't have all the "features" of a normal iframe, but may be able to work for what you need.
It should be noted that I found this technique I believe on another question on stackoverflow :).
Edit:
It should be noted that this also allows ajax stuff from within the "iframe" which is why I verify that the href doesn't equal '#'. Also this depends on the ajaxForm jquery plugin if you are planning on using the form submit stuff.