HTML - 跳转到 iframe
我有一系列像这样的链接
<li><a href="classes/journeydistance.html" target="classes">Class Name </a></li>
转到这个 iframe
<IFRAME src="classes/yaddayadda.html" style="width:400px;height:700px;" frameborder="0" name="classes" scrolling="auto">
</IFRAME>
但是 iframe 位于页面底部,链接位于顶部,中间有一堆文本。有没有一种方法可以让当人们点击课程链接时将他们跳转到 iframe?
I have a series of links like so
<li><a href="classes/journeydistance.html" target="classes">Class Name </a></li>
That goes to this iframe
<IFRAME src="classes/yaddayadda.html" style="width:400px;height:700px;" frameborder="0" name="classes" scrolling="auto">
</IFRAME>
However the iframe is at the bottom of the page, the links are at the top with a bunch of text in between. Is there a way to make it so when the person clicks the class link it jumps them to the iframe?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个可行的解决方案:(使用一点javascript)
http://jsfiddle.net/RGjCL/4/< /a>
Here is a working solution: (using a touch of javascript)
http://jsfiddle.net/RGjCL/4/
您可以通过为 iframe 提供一个 id 并在链接中添加一个主题标签来实现此目的:
我还没有测试过它,但我认为它会起作用。
You can do so by giving the iframe an id an put a hashtag in the link:
I haven't tested it but I think it will work.
好吧,我最初的想法很快就被粉碎了(想用一个技巧来做一个纯 html/css 的事情,但后来想想这是相当愚蠢的)。
由于您已经使用锚点(标签)触发了一个操作,除非您使用 JavaScript,否则您无法对其执行更多操作。
所以这里是一个jquery的有效概念证明 http://jsfiddle.net/sg3s/Wpnng/2/
这样,如果关闭 js,链接仍然可以工作,只是不会向下滚动...
我不认为只有 html/css 有办法,如果这是唯一的,我不会使用 jquery事你将加载它...
做了一个小小的改进,目标是在被单击的链接的目标属性中,但是,如果您总是想滚动到同一个 iframe,这只会使其变慢:< a href="http://jsfiddle.net/sg3s/Wpnng/3/" rel="nofollow">http://jsfiddle.net/sg3s/Wpnng/3/
Ok my initial idea was quickly crushed (wanted to do a pure html/css thing using a trick which on second thought was pretty stupid).
Since you're already triggering an action with the anchor (a tag) you can't do much more with it unless you use javascript.
So here is a working proof of concept with jquery http://jsfiddle.net/sg3s/Wpnng/2/
This way the links will still work if js is turned off it just wont scroll down...
I don't think there is a way in just html/css, I wouldn't use jquery if this is the only thing you would be loading it for...
Made a slight improvement, targetting w/e is in the target attribute of the link in question being clicked, however, if you always want to scroll to the same iframe this would just make it slower: http://jsfiddle.net/sg3s/Wpnng/3/