0
我有一个网页和所有其他网页上的iFrame我有一个按钮说“讨论”。当用户点击这个按钮时,它会将它们带到iframe页面。iFrame - 如何加载用户刚刚来的页面?
我想知道如何让iframe显示用户刚从哪里来的页面?即带有讨论按钮的页面。
这样最终用户将能够通过在iframe中查看来讨论该页面。
在此先感谢, 丹尼尔。
我有一个网页和所有其他网页上的iFrame我有一个按钮说“讨论”。当用户点击这个按钮时,它会将它们带到iframe页面。iFrame - 如何加载用户刚刚来的页面?
我想知道如何让iframe显示用户刚从哪里来的页面?即带有讨论按钮的页面。
这样最终用户将能够通过在iframe中查看来讨论该页面。
在此先感谢, 丹尼尔。
下面是一个例子。这两个文件必须位于同一个目录中。
mainpage.html
:
<html>
<body>
<script>
function gotoFramePageNormal() {
window.open('framepage.html', '_top');
}
function gotoFramePageWithVar() {
window.open('framepage.html?ref='+document.location.href, '_top');
}
</script>
<input type=button value="Discuss" onclick="gotoFramePageNormal()" /> (normal referrer; via HTTP header)<br />
<br />
<input type=button value="Discuss" onclick="gotoFramePageWithVar()" /> (with URL variable referrer)<br />
</body>
</html>
framepage.html
:
<html>
<body>
<div>
Source: <span id="srcurl">...</span>
</div>
<iframe id="theframe" width=800 height=600></iframe>
<script>
(function() {
if (document.referrer=='') { //no referrer
//parse URL variables
var a=document.location.search,b,c;
while ((a.length>0) && (a[0]=='?')) a=a.substring(1,a.length);
//split variables
a=a.split('&');
//check each variable
for (b=0; b<a.length; b++) {
//split name and value
c=a[b].split('=');
if (c[0].toLowerCase()=='ref') {
//show source url
srcurl.innerText=decodeURI(c[1]);
//set iframe source
theframe.location.href=decodeURI(c[1]);
return;
}
}
//show no source url
srcurl.innerText='none';
} else { //has referrer
//show source url
srcurl.innerText=document.referrer;
//set iframe source
theframe.location.href=document.referrer;
}
})();
</script>
</body>
</html>
的mainpage.html
使用URL可变源页传递到页帧。一般来说,这是由网络浏览器自动完成的,但它不够可靠,因为该功能可以被用户禁用。 framepage.html
将使用这两种方法来检测源页面URL。
嗨,我已经完全使用此代码,但没有运气。 http://www.biolonline.co.uk/discuss/mainpage.html <这是mainpage.html,下一个链接是framepage.html> http://www.biolonline.co.uk/discuss/framepage。 html Thansk为你提供帮助 - 如果我能得到这个工作,我会很高兴! – user1527487 2012-07-21 10:18:43