[英]iFrames: Change the root URL hit by relative URL src's
I have an iFrame on my webpage that is from the same origin as its parent page. 我的网页上有一个iFrame,它与其父页面的来源相同 。 I'm loading page into there that has a bunch of
img
, script
, link
, etc. tags in it that all have relative src
s such as src="/imgs/img.jpeg"
as opposed to src="http://mywebsite.com/imgs/img.jpeg"
. 我正在加载页面,其中有一堆
img
, script
, link
等标签,它们都有相对的 src
例如src="/imgs/img.jpeg"
,而不是src="http://mywebsite.com/imgs/img.jpeg"
。
What I want is for all of those resources to go to another server. 我想要的是将所有这些资源转到另一台服务器。 So instead of hitting
http://mywebsite.com/imgs/img.jpeg
I want them to hit http://yahoo.com/imgs/img.jpeg
or other website. 因此,我希望他们点击
http://yahoo.com/imgs/img.jpeg
或其他网站,而不是点击http://mywebsite.com/imgs/img.jpeg
。
Is there a way to change the "base URL" or whatever of the iFrame so that all the relative src
s will hit another website and get those resources, using javascript? 有没有办法更改“基本URL”或任何iFrame,以便所有相关的
src
将使用javascript访问另一个网站并获取这些资源?
Are there some cross-origin policies this would violate? 这会违反一些跨域政策吗? Definite answers please, no speculation...
答案肯定,没有猜测......
And is there a better way than to brute-force change all the src
s in the DOM and hack it all up... 还有一种更好的方法,而不是强力改变DOM中的所有
src
并将其全部破解......
Thanks y'all! 谢谢你们!
This is part of HTML5. 这是HTML5的一部分。 Just set a BASE tag in your HEAD section.
只需在HEAD部分设置BASE标记即可。 In your example it would be:
在您的示例中,它将是:
<base href="http://yahoo.com/">
This will set the base for all relative URLs. 这将为所有相对URL设置基础。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.