Reputation: 95
I have a JavaScript function
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();
}
}
This is getting stored in the noting editor. but when I see in my action class its getting stored as
<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>
Where say actual draft id was 9/1021/2015-FT-COORD-new file 12oct/3.
Hence, this draft is not being opened. I can't understand why is this happening.
Upvotes: 0
Views: 60
Reputation: 14741
You need to encode it using encodeURIComponent()
From 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).
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();
}
}
Upvotes: 1