简体   繁体   English

JavaScript函数未正确调用

[英]Javascript function not being called properly

I have a JavaScript function 我有一个JavaScript函数

function createHyperLinkDraft(){ 
    var xWin = window.opener;
    var hyperLink = document.addHyperLinkForm.hyperLinkNameDraft.value;

    if(hyperLink){

        var urlList = "openDraftFilesAction.action?draftID="+ document.addHyperLinkForm.DraftNo.value ;
        hyperLinkName = "&nbsp;<a style='text-decoration:underline;cursor:pointer' onclick=javascript:window.open('"+urlList+"','subWindow','HEIGHT=600,WIDTH=600,screenX=100,left=100,screenY=100,top=100')>"+ hyperLink +"</a>&nbsp;";

        xWin.Xinha._currentlyActiveEditor.insertHTML(hyperLinkName);

        document.addHyperLinkForm.reset();
        window.close();
    }
}

This is getting stored in the noting editor. 这将存储在注释编辑器中。 but when I see in my action class its getting stored as 但是当我在动作类中看到它被存储为

<p>l&nbsp;<a onclick="javascript:window.open('openDraftFilesAction.action? draftID=9/1021/2015-FT-COORD-new" 3?,?subwindow?,?height="600,WIDTH=600,screenX=100,left=100,screenY=100,top=100')" style="cursor: pointer; text-decoration: underline">link</a>&nbsp;</p>

Where say actual draft id was 9/1021/2015-FT-COORD-new file 12oct/3. 其中说的实际草稿ID是9/1021 / 2015-FT-COORD-新文件12oct / 3。

Hence, this draft is not being opened. 因此,该草案未公开。 I can't understand why is this happening. 我不明白为什么会这样。

You need to encode it using encodeURIComponent() 您需要使用encodeURIComponent()对其进行编码

From MDN: 从MDN:

The encodeURIComponent() method encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters). encodeURIComponent()方法通过将代表某些字符的每个实例替换为代表字符的UTF-8编码的一个,两个,三个或四个转义序列来编码统一资源标识符(URI)组件(对于字符而言将仅是四个转义序列)由两个“代理”字符组成)。

function createHyperLinkDraft() { 
    var xWin = window.opener;
    var hyperLink = document.addHyperLinkForm.hyperLinkNameDraft.value;

    if (hyperLink) {
        var urlID = document.addHyperLinkForm.DraftNo.value;
        urlID = encodeURIComponent(urlID);
        var urlList = "openDraftFilesAction.action?draftID="+ urlID;
        hyperLinkName = "&nbsp;<a style='text-decoration:underline;cursor:pointer' onclick=javascript:window.open('"+urlList+"','subWindow','HEIGHT=600,WIDTH=600,screenX=100,left=100,screenY=100,top=100')>"+ hyperLink +"</a>&nbsp;";

        xWin.Xinha._currentlyActiveEditor.insertHTML(hyperLinkName);

        document.addHyperLinkForm.reset();
        window.close();
    }
}

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

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