0

not sure if there's something wrong with this code but I was able to make it work on pure HTML Page but not when using the javascript(javascript:openDocument) on the PHP HTML Page.

<a id='edit' href='javascript:openDocument('asd.docx')' name='Btn1'>Edit</a>
3
  • 1
    href='javascript:openDocument('asd.docx')' ==> href='javascript:openDocument(\'asd.docx\')'. Notice \' escaping Commented Aug 18, 2015 at 9:45
  • Hi Thanks for responding, I tried it but it's not working too.. the error message that i'm getting when highlighting the hyper link is "javascript.openDocument(\" without the quotations. Commented Aug 18, 2015 at 9:53
  • This question is similar to: How do I properly escape quotes inside HTML attributes?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Apr 12 at 6:47

2 Answers 2

1

Try below code

<a id='edit' href="javascript:openDocument('asd.docx');" name='Btn1'>Edit</a>

Also prefer double quotes in HTML.

For PHP:

echo "<a href=\"javascript:openDocument('asd.docx')\";>";
Sign up to request clarification or add additional context in comments.

5 Comments

Are you just copying and pasting this straight into your PHP script? It needs to either be echoed or you need to break the script by using ?>, enter the html and then reopen the php script with <?php
If you want to add plain HTML in PHP then just close the PHP tag and put your plain HTML.
Hi mfisher91. Yes, I'm echoing it on PHP but it's still not working, the code I'm currently using is echo "<a href='javascript:openDocument('asd.docx')>';. It's undoubtedly working If I change href to href="asd.docx"
echo "<a href=\"javascript:openDocument('asd.docx')\";>";
Thanks but it is still not working.. when I highlight the URL it display a message on the status bar of IE like this javascript:openDocument('asd.docx') - it's not opening when I click it.. it does nothing.. when there should be when I do it using HTML..
1

As mentioned in a comment, you need to overcome the problem of having two lots of single quotes in your href part. Why? When you get to the second ', it thinks you are ending. You can do this:

<a id="edit" href="javascript:openDocument('asd.docx');"> 

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.