简体   繁体   中英

href appending current URL before navigating to new link

function setRedirect()
{
    var redirectDest = "This is additional description <a href=&quot;http://opensourceforgeeks.blogspot.in/&quot;>Click Me</a>.";
    if(redirectDest != null && redirectDest != '')
    {
        document.getElementById("RedirectDestElem").innerHTML = redirectDest;
    }
}

redirectDest is populated from Spring controller. So the function is actually

function setRedirect()
{
    var redirectDest = "${redirectDest}";
    if(redirectDest != null && redirectDest != '')
    {
        document.getElementById("RedirectDestElem").innerHTML = redirectDest;
    }

}

This appends current url base address to http://opensourceforgeeks.blogspot.in and then redirects. I dont want this to happen. I have to convert " to &quot; in Java code (escape it) so that my java script does not break. Otherwise it will be

var redirectDest = "This is additional description <a href="http://opensourceforgeeks.blogspot.in/">Click Me</a>.";

which will break.

Why don't you enclose redirectDest in single quotes?

var redirectDest = '${redirectDest}';

you can use the escape sequence "\\"

so your text will be like below:

var redirectDest = "This is additional description <a href=\"http://opensourceforgeeks.blogspot.in/\">Click Me</a>.";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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