未捕获的TypeError ("no access")问题与jquery取决于浏览器导航


Uncaught TypeError ("no access") issue with jquery depending on browser navigation

我试着研究过这个问题,但是我完全被难住了。我认为这可能与同源策略有关,但我不知道它与我的代码有什么关系。

我有一个运行jquery和bootstrap的php站点,它在mysite/build.php呈现动态web表单。包含脚本调用的头部如下所示:

<head>
    <!-- jQuery -->
    <script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
    <!-- Bootstrap Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">        
    
    <!-- Bootstrap Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    
    <!-- app CSS -->
    <link href="/css/styles.css" rel="stylesheet"/>
    
    <!-- Are-You-Sure dirty form checker -->
    <script src="/js/are-you-sure.js"></script>
    
    <!-- app JavaScript -->
    <script src="/js/build-edit-scripts.js"></script>
    
    <!-- obtain sheet data for edit mode -->
    <?php if (isset($items)): ?>
        <script type="text/javascript">
            var items = <?php echo json_encode($items) ?>; 
            var sheetinfo = <?php echo json_encode($sheetinfo) ?>;
            var slug = <?php echo json_encode($slug) ?>;
        </script>
    <?php endif ?>
    
    <!-- obtain single block and bullet elements for js -->
    <script> var blockHTML = <?php echo json_encode($blockhtml) ?>; var bulletHTML = <?php echo json_encode($bullethtml) ?>;</script>
    
    <title><?= (isset($sheetinfo)) ? "Edit: ".htmlspecialchars($sheetinfo['name']) : "Shopping List Generator"; ?></title>
    
</head>

然后我的自定义javascript (build-edit-scripts.js)的开始如下所示

//execute when DOM fully loaded 
$(function() {
// enable areYouSure plugin to detect dirty form changes
$('#myform').areYouSure();
// mark form as dirty any time any text input changes
$(document).on('change', 'input:text', function() {
    $('#myform').addClass('dirty');
});
    // create empty array for existing slugs
    var slugs = [];
    
    // initiate ajax request to get dir listing of existing sheets
    $.ajax({
        url: "json-io.php",
     
        data: {
            purpose: "sheetlist"
        },
        type: "POST",
        dataType : "json"
    })
    // if successful
    .done(function(dirjson) {
            slugs = dirjson;
          })
    // if failure
    .fail(function( xhr, status, errorThrown ) {
            alert( "Server Error" );
            console.log( "Error: " + errorThrown );
            console.log( "Status: " + status );
            console.dir( xhr );
    });         
    // give focus to title field
    $("#title").focus();

当我最初加载build.php或硬刷新它时,我没有问题。但是,每当我导航到外部站点,然后点击返回导航并返回build.php时,我都会收到以下控制台错误:

Uncaught TypeError: no access (@ jquery-3.1.0.min.js:2)

之后是jquery加载不当的问题

Uncaught Error: Bootstrap的JavaScript需要jQuery (@ Bootstrap .min.js:6)

Uncaught ReferenceError: jQuery is not defined (@ are-you-sure.js:192)

Uncaught ReferenceError: $ is not defined (@ build-edit-scripts.js:12)

从这里开始,我的JS的其余部分都不起作用。我最初认为这可能是由于ajax请求的问题,但是即使我完全删除了ajax请求,问题仍然存在。任何见解都将是非常感激的,因为我似乎无法针对问题发生的地方。谢谢。

遇到这个,因为我有(或有)相同的错误在Chrome浏览器导航时使用返回按钮从链接。只要在导航后加载页面并且任何脚本尝试访问窗口对象,就会发生此错误。

这个页面是仅有的两个引用这个错误信息("未捕获的TypeError: no access")之一,我可以在网络上的任何地方找到-另一个是一个Chrome错误报告,据说是一年前修复的。不要认为它与jQuery有任何关系(我们的是纯javascript),但不知道是什么原因导致它或它的意思,这似乎是一个非常模糊的错误。重新启动浏览器后,这个错误不再重现,但它已经看到了不止一次。只要脚本代码试图读取窗口对象的任何窗口属性,就会发生这种情况。如果有人知道这个错误意味着什么,什么可能导致这个错误,请张贴这个

我唯一能想到的是你的CORS没有正确配置,虽然它看起来很好,或者你的文档没有完全加载当你试图访问jQuery,它看起来像你的代码应该加载良好。

您确定需要在脚本包含的末尾使用integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"标记吗?这些参数可能不是正确的,并且可能导致一些冲突。

我在YouTube上经常遇到这种情况。这让我认为这是一个Chrome的错误,因为我很确定他们会有所有的东西,如CORS配置正确。

重新加载页面通常可以修复它,但这种情况经常发生(我的浏览器已经打开好几天了)。就像其他人说的那样,点击后退按钮经常会导致这个问题,但YouTube加载页面的方式,我甚至只是点击视频回到YouTube主页。

我的建议是再次提出这个错误,因为它现在发生在谷歌自己的网站上。

这是来自Chrome控制台的错误-我宁愿认为这是在页面脚本运行之前发生的:

(unknown) Uncaught TypeError: no access       (unknown)
    at <anonymous>:10:29
    at <anonymous>:58:5
(index):1 Uncaught TypeError: no access       (index.js:1)
    at (index):1
(index):11 Uncaught TypeError: no access
    at Object.k [as runBeforeBodyIsReady] ((index):11)
    at (index):16
scheduler.js:10 Uncaught TypeError: no access
    at scheduler.js:10
    at scheduler.js:40