HTML - 跳转到 iframe

发布于 2024-12-05 12:12:40 字数 413 浏览 0 评论 0原文

我有一系列像这样的链接

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧街凉风 2024-12-12 12:12:40

这是一个可行的解决方案:(使用一点javascript)

http://jsfiddle.net/RGjCL/4/< /a>

<ul>
    <li>
        <a href="javascript:void(0)"
            onclick="IFrameScroll('http://www.asdf.com')">Class Name</a>
    </li>
</ul>

<script type="text/javascript">
    function IFrameScroll(link){
        window.classes.location=link; 
        window.location.hash='classes'
    }
</script>

Here is a working solution: (using a touch of javascript)

http://jsfiddle.net/RGjCL/4/

<ul>
    <li>
        <a href="javascript:void(0)"
            onclick="IFrameScroll('http://www.asdf.com')">Class Name</a>
    </li>
</ul>

<script type="text/javascript">
    function IFrameScroll(link){
        window.classes.location=link; 
        window.location.hash='classes'
    }
</script>
一江春梦 2024-12-12 12:12:40

您可以通过为 iframe 提供一个 id 并在链接中添加一个主题标签来实现此目的:

<iframe id="myIframe" rc="classes/yaddayadda.html" style="width:400px;height:700px;" frameborder="0" name="classes" scrolling="auto"></iframe>
And the link: <li><a href="classes/journeydistance.html#myIframe" target="classes">Class Name </a></li>

我还没有测试过它,但我认为它会起作用。

You can do so by giving the iframe an id an put a hashtag in the link:

<iframe id="myIframe" rc="classes/yaddayadda.html" style="width:400px;height:700px;" frameborder="0" name="classes" scrolling="auto"></iframe>
And the link: <li><a href="classes/journeydistance.html#myIframe" target="classes">Class Name </a></li>

I haven't tested it but I think it will work.

一抹淡然 2024-12-12 12:12:40

好吧,我最初的想法很快就被粉碎了(想用一个技巧来做一个纯 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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文