jQuery强制为iframe设置src属性 [英] jQuery Force set src attribute for iframe
问题描述
我有一个主页(实际上是一个JSP),其中有一个iframe作为;
I have a main page (actually a JSP) with an iframe inside it as;
<iframe name="abc_frame" id="abc_frame" src="about:blank" frameborder="0" scrolling="no"></iframe>
现在主页上有多个链接(通过JSP动态呈现),可以尝试设置src到一些URL ...
Now there are multiple links on the main page (rendered dynamically via JSP) which can try to set the src to some URL...
现在我的问题是,使用jQuery(可能是live()),我可以覆盖它,以src对于abc_frame的属性总是有一些特定的值(例如somefixedURL)
Now my question is,using jQuery (may be live()), can I override that in such a way that the "src" attribute for abc_frame would always have some particular value (e.g. "somefixedURL")
我无法捕获链接点击,因为它是通过一些Java代码完全动态创建的,因此我我试图覆盖iframe src?
I cannot capture the link clicking, as it is completely dynamically created via some Java code and hence I am trying to override the iframe src ?
推荐答案
使用 attr
$('#abc_frame').attr('src', url)
这样,您可以获取并设置每个HTML标签属性。请注意,还有 .prop()
。有关差异,请参阅 .prop()vs .attr()。简短版本: .attr()
用于HTML源代码和 .prop()
中的属性适用于所有附加到DOM元素的JavaScript。
This way you can get and set every HTML tag attribute. Note that there is also .prop()
. See .prop() vs .attr() about the differences. Short version: .attr()
is used for attributes as they are written in HTML source code and .prop()
is for all that JavaScript attached to the DOM element.
这篇关于jQuery强制为iframe设置src属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!