我在iframe中有一个自动生成照片库,可以更改在表单选择中保留的图像的类别。想法是通过获取网址找到他们选择的图像,并通过php将其传递到下一页。我可以从iframe获取网址,但是当我尝试将值传递到下一页时,我得到:空白。当我使用隐藏表单字段值中的警报时,它也在同一页面上执行此操作。我认为这是隐藏形式价值的问题。
因此,如果您加载下面的页面,隐藏表单值的警报将显示为空白。然后我有2个按钮,1个处理表格并显示:下一页的空白;另一个在分配隐藏字段值之前从函数值中获取url(这个值是正确的值)。一旦将url值分配给隐藏字段,它就永远不会成为它。这是不可能的,还是我做错了?
更新我发现该值与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>
答案 0 :(得分:0)
你试过了吗?
if(url==undefined){ return( frame.contentWindow.document.src );}
或者基本上,使用xxx.document.src
或xxx.document.location
代替location.href
进行尝试?