简体   繁体   English

错误:拒绝访问属性“ $”的权限

[英]Error: Permission denied to access property '$'

everybody. 每一个人。 I have the following situation: 我有以下情况:

I have: http://example.com/ and http://example.com/new 我有: http : //example.com/http://example.com/new

In example.com, I have some forms that I load in example.com/new domain with fancybox iframe. 在example.com中,我使用fancybox iframe在example.com/new域中加载了一些表格。

My form, basically shows some fields for the user to enter his pessoal data, like name, phone and etc... After he submit that, I show some user agreement terms that comes from database and a checkbox for the user to say that he agree with the terms. 我的表单基本上显示了一些供用户输入比索数据的字段,例如姓名,电话等。在他提交之后,我显示了一些来自数据库的用户协议条款和一个复选框,供用户说同意条款。

After he check and submit, I want to alert some sucess message and the fancybox modal/iframe to close and thats it. 他检查并提交后,我想提醒一些成功消息,并且fancybox modal / iframe关闭,仅此而已。

In the form page, i've loaded jquery, and bootstrap. 在表单页面中,我已经加载了jquery和bootstrap。 So, when the user agree, I print: 因此,当用户同意时,我打印:

<?php
     echo "
          <script>
          alert('Some success message!');

          $(document).ready(function(){
              parent.$.fancybox.close();
          });
         </script>
     ";
?>

I have three forms, in one, works, in the other two, i get: 我有三种形式,一种是作品,另外两种是:

Error: Permission denied to access property '$'

The only difference between the form that works and the other two, is that in the form that works, i don't have the agreement terms coming from database, only the checkbox. 有效形式与其他两种形式之间的唯一区别是,在有效形式中,我没有来自数据库的协议条款,只有复选框。

I could put my entire code here, but would be a giant question. 我可以将整个代码放在这里,但这将是一个巨大的问题。 But if you guys need, I can update. 但是如果你们需要,我可以更新。

Sorry for my english and forgive-me if I was not clear. 对不起,如果我不清楚我的英语,请原谅我。

UPDATE: 更新:

<!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>

This is a browser security thing. 这是浏览器的安全性。 While there's a few ways around it, the best one is probably to use the postMessage API . 尽管有几种解决方法,但是最好的方法可能是使用postMessage API

On your example.com parent page, add some code like this: 在您的example.com父页面上,添加如下代码:

function handleMessageFromiFrame(event) {
  alert('Some success message: ' + event.data);
  //$.fancybox.close();
}

window.addEventListener("message", handleMessageFromiFrame, false);

And, then on your child example.com/new iframe, add code like this: 然后,在您的孩子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);

Here's an example of it in action: 这是一个实际的例子:

When you click the button in the child page, it uses postMessage to notify the parent. 当您单击子页面中的按钮时,它将使用postMessage通知父页面。 Then the parent listens for the message and does whatever action you want. 然后,父级侦听该消息,然后执行所需的任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM