Javascript 按包含iframe的页面识别在iframe中导航到的链接
我有一个网站,所有的导航都发生在iframe中。所有页面都本地存储在服务器上 html代码的简化版本为:Javascript 按包含iframe的页面识别在iframe中导航到的链接,javascript,jquery,html,css,iframe,Javascript,Jquery,Html,Css,Iframe,我有一个网站,所有的导航都发生在iframe中。所有页面都本地存储在服务器上 html代码的简化版本为: >> index.php <html> <head> </head> <body> <table><tr><td> <iframe src="link.php" width=599 height=350 frameborder=0 scrolling=no name="vframe">
>> index.php
<html>
<head>
</head>
<body>
<table><tr><td>
<iframe src="link.php" width=599 height=350 frameborder=0 scrolling=no name="vframe"></iframe>
<td>
<img src="pic.jpg">
</body>
</html>
我想做的是,让父页面以某种方式持有iframe,以识别iframe中的页面,并使图像的显示取决于此,而不是上面的hack。我认为这是一种更可靠的方式,不受用户操纵链接的影响
另一方面,如果有一种方法可以在地址栏中没有显示链接的情况下在链接中找到“locate”,那么这可能是一种折衷方案。但据我所知,这是不可能的
====
编辑
我发现:
document.getElementById("iframe_id").contentWindow.location.href
但我不知道如何实施
我试过了
<script>document.write(document.getElementById("vframe").contentWindow.location.href );</script>
document.write(document.getElementById(“vframe”).contentWindow.location.href);
在身体和头部
但不显示iframe链接
我试过这个:
<html>
<head>
<script>
function getLink()
{
var x=document.getElementById("vframe").contentWindow.location.href;
}
</script>
</head>
<body>
<iframe src="start.php" width=599 height=350 frameborder=0 scrolling=no name="vframe"></iframe>
</body>
</html>
<html>
<head>
</head>
<body>
<iframe src="start.php" width=599 height=350 frameborder=0 scrolling=no id="vframe"></iframe>
<script>document.write(document.getElementById("vframe").contentWindow.location.href);</script>
</body>
</html>
函数getLink()
{
var x=document.getElementById(“vframe”).contentWindow.location.href;
}
但是如果它应该是有效的,我不知道如何“读取”VarX的结果
我试过这个:
<html>
<head>
<script>
function getLink()
{
var x=document.getElementById("vframe").contentWindow.location.href;
}
</script>
</head>
<body>
<iframe src="start.php" width=599 height=350 frameborder=0 scrolling=no name="vframe"></iframe>
</body>
</html>
<html>
<head>
</head>
<body>
<iframe src="start.php" width=599 height=350 frameborder=0 scrolling=no id="vframe"></iframe>
<script>document.write(document.getElementById("vframe").contentWindow.location.href);</script>
</body>
</html>
document.write(document.getElementById(“vframe”).contentWindow.location.href);
但结果是“关于:空白”。如果我将它放在头部或iframe上方,则没有结果…vframe是名称,您需要将其设置为idtry
document.write(document.getElementById(“vframe”).src
好的,这是一个进展…但是现在的问题是当我导航到iframe内部的另一个页面时,您的代码剪贴只读取静态链接,而不读取新的iframe url…并且所有导航都在同一个服务器上…谢谢给出一个名称=“vframe”属性设置为iframe,然后您可以访问返回“about:blank”的window.vframe.location.href
。这是一个棘手的问题!感谢您的回复