将iframe url传递到下一页


passing iframe url to next page

我在iframe中有一个自动生成的照片库,它根据表单选择更改图像的类别。这个想法是通过获取url找到他们选择的图像,并通过php将其传递到下一个页面。我可以从iframe获取url,但当我尝试将值传递到下一页时,我得到大约:空白。当我使用隐藏表单字段值的警报时,它也会在同一页面上执行。我认为这是隐藏形式价值的问题。

所以如果你加载下面的页面一个警告从隐藏表单值将出现,关于空白。然后我有2个按钮,1,处理的形式,并显示约:空白在下一页;另一个在分配隐藏字段值(这是正确的值)之前从函数值获取url。url值一旦被分配给隐藏字段就不会生效。所以这是不可能的还是我做错了?

update我发现IE正确传递了值,只是Firefox由于某种原因没有传递值到下一页。请有人告诉我为什么这是,有一个跨浏览器的解决方案?

index.php
<html>
<head>
<script type="text/javascript" runat="server">
//this function gets url from iframe on same domain
  function framehref(frame,url){
  if(typeof(frame)=='string'){//find iframe (will not find a frame):
  frame=document.getElementById(frame);
}
  if(frame.tagName=='IFRAME'){//iframe:
  if(url==undefined){ return( frame.contentWindow.document.location );}
  frame.contentWindow.document.location.href=url;
}else{//frame:
  if(url==undefined){ return( frame.document.location );}
  frame.document.location.href=url;
}
}
</script>
</head>
<body>
<form method="post" action="modify.php" name="step1" border="0"><br/>

<iframe src="http://localhost/iframemain.php/" id="myIframe" name="myIframe"     width="510" height="400"></iframe>

<div id="mydiv"></div>

<input type="submit" value="nextpage!">
<input type="button" value="get url!" onclick="alert (framehref('myIframe'));" >
<script type="text/javascript" runat="server">
var image = document.createElement("input");
image.setAttribute("type", "hidden");
image.setAttribute("name", "url");
image.setAttribute("id","url");
image.setAttribute("value", framehref("myIframe"));
document.getElementById("mydiv").appendChild(image);
alert (document.getElementById("url").value)
</script>
</form>
</body>
</html>

这里是modify.php

<?php
$url = $_REQUEST['url'] ;
?>
<html>
<head>
</head>
<body>
<?php
$url = $_POST['url'] ;
echo "<b>url:</b> $url"?>
</body>
</html>

你试过了吗:

if(url==undefined){ return( frame.contentWindow.document.src );}

或者基本上,用xxx.document.srcxxx.document.location代替location.href ?