0

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 = "&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.

Hence, this draft is not being opened. I can't understand why is this happening.

TheMohanAhuja
1,8752 gold badges19 silver badges30 bronze badges
asked Nov 6, 2015 at 6:17
2
  • Do you have the last bracket closed? Commented Nov 6, 2015 at 6:22
  • Create a fiddle and reproduce the error there. Commented Nov 6, 2015 at 6:25

1 Answer 1

1

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 = "&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();
 }
}
Drenmi
8,8064 gold badges46 silver badges52 bronze badges
answered Nov 6, 2015 at 6:27
Sign up to request clarification or add additional context in comments.

4 Comments

It helped, but can you explain what is encodeURIComponent?
i added it in the answer. it is a standard javascript function.
Actually there is a problem in it, In the first time, the link does not get opened. But, on refreshing the page its getting opened
can you just add window.open(urlList); just to see if it is a problem of your xWin object or directly a link problem? there are little information to understand the problem here.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.