1

I am writing a javascript function to open a link to download a pdf. (The function will check for a string, if the condition satisfies it will open a link, if the condtion doesnot satisfy it will open another link).

<tr>
    <td align="center">
         <a href="#" onclick="openPdfReport()" style="text-decoration: none"><font size="2" color="RED"><b><u>View Report </u></b></font></a>
    </td>
</tr>


function openPdfReport()
    {
        var nameOnly = "";
                //This value s is only for testing puropse
        var s = "/testdata/e-Form/app/Eforms/Certificates/1234/abcdcertificate12345.pdf";
        var totalLength = s.length();
        if(totalLength>60)
        {
            nameOnly=s.substring(45, 60);

            String ackNoOnly = s.substring(60, s.indexOf("."));

            if(nameOnly.equalsIgnoreCase("abcdcertificate"))
            {
                window.open("http://www.abc.com/abc.pdf",'_blank');
            }
            else
            {
                window.open("http://www.abc.com/abc.xls",'_blank');
            }

        }
        else
        {
            window.open("http://www.abc.com/abc.xls",'_blank');
        }
    }

But when I click on the View Report link, the report is not downloading. Not able to find where i am missing. Any help is highly appreciated.

Thanks and Regards

1
  • 2
    Why is this tagged as java/jsp, this is an HTML/Javascript question. Commented Jan 19, 2014 at 15:27

1 Answer 1

3

There seems to be some Javathink leakage;

  • String ackNoOnly should be var ackNoOnly
  • length is a property not a method so s.length;
  • equalsIgnoreCase is a java method, in js; if (nameOnly.toLowerCase() === "ab..
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.