각자 모두. 다음과 같은 상황이 있습니다.
내가 가진 : http://example.com/ 및 http://example.com/new
example.com에는 fancybox iframe을 사용하여 example.com/new 도메인에로드하는 몇 가지 양식이 있습니다.
내 양식은 기본적으로 사용자가 이름, 전화 등과 같은 페소 데이터를 입력 할 수있는 몇 가지 필드를 표시합니다. 제출 한 후 데이터베이스에서 가져온 사용자 계약 조건과 사용자가 약관에 동의합니다.
그가 확인하고 제출 한 후에는 성공 메시지와 fancybox 모달 / iframe이 닫히도록 경고하고 싶습니다.
양식 페이지에서 jquery와 부트 스트랩을로드했습니다. 따라서 사용자가 동의하면 다음을 인쇄합니다.
<?php
echo "
<script>
alert('Some success message!');
$(document).ready(function(){
parent.$.fancybox.close();
});
</script>
";
?>
나는 세 가지 형태를 가지고 있는데 하나는 작동하고 다른 두 가지 형태는 다음과 같습니다.
Error: Permission denied to access property '$'
작동하는 양식과 다른 두 양식의 유일한 차이점은 작동하는 양식에서 데이터베이스에서 오는 계약 조건이없고 확인란 만 있다는 것입니다.
여기에 전체 코드를 넣을 수는 있지만 큰 질문이 될 것입니다. 하지만 필요한 경우 업데이트 할 수 있습니다.
내 영어에 대해 미안하고 명확하지 않으면 용서하십시오.
최신 정보:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<?php
/* Connect with DB */
require_once('require/conectar.php');
if(!empty($_POST))
foreach($_POST as $k => $v)
$$k = $v;
?>
<script type="text/javascript" src="http://example.com/new/assets/js/jquery.js"></script>
</head>
<body>
<?php if(!isset($agree) and !isset($next)): ?>
<h1>The form</h1>
<form method="post" action="">
<label>Your name:</label>
<input type="text" name="name">
<br>
<label>Your email:</label>
<input type="text" name="email">
<br>
<input type="submit" name="next">
</form>
<?php
else:
$error = (!isset($name)) ? true : false;
$error = (!isset($name)) ? true : false;
if($error)
{
echo '<script>You must fill all fields before submit.</script>';
exit;
}
$qrr = mysql_query("SELECT * FROM `terms`");
$terms = mysql_fetch_object($qrr);
?>
<h1>Terms:</h1>
<?php echo $terms->content; ?>
<form method="post" action="">
<input type="hidden" value="<?php echo $name; ?>" name="name">
<input type="hidden" value="<?php echo $email; ?>" name="email">
<input type="checkbox" value="1" name="accept"> I agree.
<input type="submit" name="agree">
</form>
<?php
endif;
if(isset($agree))
{
/*
Here i mail me the user data.
*/
echo "
<script>
alert('Soliciação Realizada com sucesso!');
$(document).ready(function(){
parent.$.fancybox.close();
});
</script>
";
}else
{
echo "<script>alert('You need to agree with the terms to proceed.');</script>";
}
?>
</body>
</html>
이것은 브라우저 보안 문제입니다. 몇 가지 방법이 있지만 가장 좋은 방법은 postMessage API 를 사용하는 것입니다 .
example.com 상위 페이지에서 다음과 같은 코드를 추가합니다.
function handleMessageFromiFrame(event) {
alert('Some success message: ' + event.data);
//$.fancybox.close();
}
window.addEventListener("message", handleMessageFromiFrame, false);
그런 다음 자식 example.com/new iframe에서 다음과 같은 코드를 추가합니다.
var parentOrigin = "*"; // set to http://example.com/ or whatever for added security.
function sendMessageToParent(){
parent.postMessage("button clicked", parentOrigin);
}
$('#submit-btn').click(sendMessageToParent);
다음은 실제 작동의 예입니다.
자식 페이지에서 버튼을 클릭 postMessage
하면 부모에게 알립니다. 그런 다음 부모는 메시지를 듣고 원하는 작업을 수행합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다