我有一个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 = " <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> ";
xWin.Xinha._currentlyActiveEditor.insertHTML(hyperLinkName);
document.addHyperLinkForm.reset();
window.close();
}
}
这将存储在注释编辑器中。但是当我在我的动作类中看到它被存储为
<p>l <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> </p>
凡说实际草案ID为9/1021/2015-FT-COORD-新文件12oct / 3.
因此,该草案尚未公开。我不明白为什么会这样。
答案 0 :(得分:1)
您需要使用encodeURIComponent()
来自MDN:
encodeURIComponent()方法通过将某些字符的每个实例替换为表示UTF-8编码的一个,两个,三个或四个转义序列来编码统一资源标识符(URI)组件。字符(对于由两个&#34;代理&#34;字符组成的字符,只有四个转义序列。)
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 = " <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> ";
xWin.Xinha._currentlyActiveEditor.insertHTML(hyperLinkName);
document.addHyperLinkForm.reset();
window.close();
}
}