簡體   English   中英

錯誤:拒絕訪問屬性“ $”的權限

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

每一個人。 我有以下情況:

我有: http : //example.com/http://example.com/new

在example.com中,我使用fancybox iframe在example.com/new域中加載了一些表格。

我的表單基本上顯示了一些供用戶輸入比索數據的字段,例如姓名,電話等。在他提交之后,我顯示了一些來自數據庫的用戶協議條款和一個復選框,供用戶說同意條款。

他檢查並提交后,我想提醒一些成功消息,並且fancybox modal / iframe關閉,僅此而已。

在表單頁面中,我已經加載了jquery和bootstrap。 因此,當用戶同意時,我打印:

<?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通知父頁面。 然后,父級偵聽該消息,然后執行所需的任何操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM