iframe / href困难(Iframe/href difficulties)

编程入门 行业动态 更新时间:2024-10-27 05:22:21
iframe / href困难(Iframe/href difficulties)

简而言之,我们有一个带有iframe的页面,我想动态定位页面URL。

为简单起见,页面位于http://1/2/3.aspx iframe将位于3.aspx页面上,而iframe指向完全不同的URL,例如http:// 100/101 / 102.html

我想将iframe定位到http:// 1/2 / “some URL”

一位同事建议使用window.location.parent进行内联javascript,但我无法弄清楚如何实现这一点。 在链接的href标记中使用通常的../只会导致我在框架的上下文中向上导航(到101,100,依此类推)。

一如既往,感谢社区为您的时间。

编辑:如果可能的话,我想使用内联javascript。

In short, we have a page with an iframe, and I want to target the page URL dynamically.

For simplicity, the page is located at http://1/2/3.aspx The iframe would be on the 3.aspx page, and the iframe points to a completely different URL, let's say http://100/101/102.html

I want to target the iframe to go to http://1/2/"some URL"

A coworker suggested inline javascript using window.location.parent, but I can't figure out how to implement this. Using the usual ../ in the link's href tag only results in me navigate up within the frame's context (to 101, 100, so on).

As always, thank you to the community for your time.

EDIT: I would like to use inline javascript for this if at all possible.

最满意答案

我想你的意思是这样的

<iframe id="ifr" src=""></iframe> <script> document.getElemenById("ifr").src = "http://1.2.3/page.html"; </script>

更新

要使用iframe父级的位置数据,您可以这样做

<iframe id="ifr" src=""></iframe> <script> var parenturl = parent.location.href; var newurl = parenturl.replace("from-this","to-this"); document.getElemenById("ifr").src = newurl; </script>

I guess you mean something like this

<iframe id="ifr" src=""></iframe> <script> document.getElemenById("ifr").src = "http://1.2.3/page.html"; </script>

Update

To use location data from the iframe's parent, you can do like this

<iframe id="ifr" src=""></iframe> <script> var parenturl = parent.location.href; var newurl = parenturl.replace("from-this","to-this"); document.getElemenById("ifr").src = newurl; </script>

更多推荐

本文发布于:2023-08-02 10:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1375473.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:困难   href   iframe   Iframe   difficulties

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!