简体   繁体   English

Iframe 内部链接到嵌入的网站

[英]Iframe inside link to a website that is embedded on

I have an iframe from site1.com embedded on a website site2.com and in that iframe I have a link to /page.html When I click on that link it takes me to the page of where the iframe comes from site1.com/page.html and I want to take me to a link on the current site site2.com/page.html. I have an iframe from site1.com embedded on a website site2.com and in that iframe I have a link to /page.html When I click on that link it takes me to the page of where the iframe comes from site1.com/ page.html 我想带我到当前站点 site2.com/page.html 上的链接。 I this possible, maybe with JavaScript?我这可能,也许是 JavaScript?

Thank you.谢谢你。

Try setting the base element within your iframe.尝试在 iframe 中设置base元素。

<base href="http://site1.com">
<a href="/page.html">Link</a>

The hostname of the parent window can be accessed by document.referrer , which can be injected to the DOM with JavaScript like this:父 window 的主机名可以通过document.referrer访问,可以像这样使用 JavaScript 注入 DOM:

var baseElement = document.createElement('base');
baseElement.setAttribute('href', document.referrer);
document.querySelector("head").appendChild(baseElement);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM