Javascript在谷歌浏览器中不能正常工作

Javascript does not work fine in google chrome

本文关键字:工作 常工作 谷歌浏览器 不能 Javascript      更新时间:2023-09-26

我在HelpNDoc个人版的帮助下创建了一个HTML文档 http://www.helpndoc.com/

我使用了随它提供的默认模板,该模板在几乎所有浏览器中加载良好,除了谷歌浏览器,模板无法加载,因为我在 HTML 方面不是那么高级,我认为您可以提供一些帮助。

错误:

Unsafe JavaScript attempt to access frame with URL file:///C:/Users/lenovo        
/Documents     /HelpNDoc/Output/html/testingproject.html from frame with URL   
file:///C:/Users/lenovo/Documents/HelpNDoc/Output/html/toc.html. Domains,   
protocols and ports must match.
toc.html:36
Uncaught TypeError: Cannot call method 'lastIndexOf' of undefined toc.html:36
Unsafe JavaScript attempt to access frame with URL file:///C:/Users/lenovo  
/Documents/HelpNDoc/Output/html/toc.html from frame with URL file:///C:/Users
/lenovo/Documents/HelpNDoc/Output/html/Introduction.html. Domains, protocols and 
ports must match.
Introduction.html:27
Unsafe JavaScript attempt to access frame with URL file:///C:/Users/lenovo   
/Documents/HelpNDoc/Output/html/toc.html from frame with URL file:///C:/Users   
/lenovo/Documents/HelpNDoc/Output/html/Systemrequirements.html. Domains,  
protocols    and ports must match.
Systemrequirements.html:27
Unsafe JavaScript attempt to access frame with URL file:///C:/Users/lenovo 
/Documents/HelpNDoc/Output/html/toc.html from frame with URL file:///C:/Users/lenovo
/Documents/HelpNDoc/Output/html/Gettinghelp.html. Domains, protocols and ports  
must   match.
Gettinghelp.html:27

目录.html看起来-我正在第 36 行之前和之后添加内容

<script type="text/javascript" src="js/searchdata.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.17.custom.min.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<script type="text/javascript" src="js/jquery.dynatree.min.js"></script>
<script type="text/javascript" src="js/hndjsse.js"></script>
<script type="text/javascript">
var bSearchDataLoaded = true;
var sHelpIdToActivate = '';
$(document).ready(function()
{
   var sAnchorName = 
   top.location.href.substring(top.location.href.lastIndexOf("#") + 1, 
   top.location.href.length);
        var nSelectedTab = 0;
        if (sAnchorName == '_index') nSelectedTab = 1
        else if (sAnchorName == '_search') nSelectedTab = 
    2;          
        $("#tabs").tabs({
            selected: nSelectedTab,
            select: function(event, ui) { HideKwPopup(); }
        });
        // Toc
        $("#tab-toc").dynatree({
            clickFolderMode: 1,
            debugLevel: 0,
            imagePath: 'css/dynatree/chm/',
            onActivate: function(node){
                if ($("#tab-keywords") && $("#tab-
keywords").dynatree && $("#tab-keywords").dynatree("getTree") && $("#tab-
keywords").dynatree("getTree").activateKey)
                    $("#tab-
keywords").dynatree("getTree").activateKey(null);
                if(node.data.href && node.data.href != '#'){
                    window.open(node.data.href, 
node.data.target);
                }
            }
        });

简介.html看起来-我在27行前后添加了行

</style>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/hnd.js"></script>
<script type="text/javascript"><!--
if (top.frames.length == 0)
{
            var sTopicUrl = 
          top.location.href.substring(top.location.href.lastIndexOf("/") + 1, 
          top.location.href.length);
            top.location.href = "testingproject.html?" + sTopicUrl;
        }
        else if (top && top.FrameTOC && top.FrameTOC.SelectTocItem)
        {
            top.FrameTOC.SelectTocItem("Introduction");
        }
</script>
</head>

系统要求.html看起来像

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/hnd.js"></script>
<script type="text/javascript"><!--
if (top.frames.length == 0)
        {
            var sTopicUrl = 
top.location.href.substring(top.location.href.lastIndexOf("/") + 1, 
top.location.href.length);
            top.location.href = "testingproject.html?" + sTopicUrl;
        }
        else if (top && top.FrameTOC && top.FrameTOC.SelectTocItem)
        {
            top.FrameTOC.SelectTocItem("Systemrequirements");
        }
    </script>
 </head>

获得帮助.html看起来像——

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/hnd.js"></script>
<script type="text/javascript"><!--
    if (top.frames.length == 0)
    {
        var sTopicUrl = 
 top.location.href.substring(top.location.href.lastIndexOf("/") + 1, 
 top.location.href.length);
        top.location.href = "testingproject.html?" + sTopicUrl;
    }
    else if (top && top.FrameTOC && top.FrameTOC.SelectTocItem)
    {
        top.FrameTOC.SelectTocItem("Gettinghelp");
    }
</script>
</head>

任何帮助都非常感谢。谢谢艾迪

这只是

toc.html,但如果这解决了该文件的问题,我很感兴趣:

<script type="text/javascript" src="js/searchdata.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.17.custom.min.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<script type="text/javascript" src="js/jquery.dynatree.min.js"></script>
<script type="text/javascript" src="js/hndjsse.js"></script>
<script type="text/javascript">
var bSearchDataLoaded = true;
var sHelpIdToActivate = '';
$(document).ready(function()
{
var sAnchorName = 
top.location.href.substring(top.location.href.lastIndexOf("#") + 1, 
top.location.href.length);
var nSelectedTab = 0;
if (sAnchorName == '_index'){ 
    nSelectedTab = 1
}
else if (sAnchorName == '_search'){
    nSelectedTab = 2;          
    $("#tabs").tabs({
        selected: nSelectedTab,
        select: function(event, ui) { HideKwPopup(); }
    });
}
// Toc
$("#tab-toc").dynatree({
    clickFolderMode: 1,
    debugLevel: 0,
    imagePath: 'css/dynatree/chm/',
    onActivate: function(node){
        if ($("#tab-keywords") && $("#tab-keywords").dynatree && $("#tab-keywords").dynatree("getTree") && $("#tab-keywords").dynatree("getTree").activateKey){
            $("#tab-keywords").dynatree("getTree").activateKey(null);
            if(node.data.href && node.data.href != '#'){
                window.open(node.data.href, node.data.target);
            }
        }
    }
});
});

如果这有效,那只是在某处错过括号的情况......如果不是,这可能是一个更深层次的问题,我无法帮助:)

希望这有帮助

此问题是由于本地启动某些JavaScript时Google Chrome的安全限制。当文档上传到 Web 服务器时,不会发生这种情况。这里对此进行了解释:http://www.helpndoc.com/sites/default/files/documentation/html/index.html?GoogleChromeshowsanerrorwhensear.html

另外@powtac是对的,这是重复的: 不安全的JavaScript尝试使用URL访问框架