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>
2 Answers 2
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
mfisher91
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
Dhruv
If you want to add plain HTML in PHP then just close the PHP tag and put your plain HTML.
Wilfrendo Gohing
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"
Dhruv
echo "<a href=\"javascript:openDocument('asd.docx')\";>";
Wilfrendo Gohing
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..
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');">
answered Aug 18, 2015 at 9:54
mfisher91
8071 gold badge8 silver badges23 bronze badges
Comments
default
href='javascript:openDocument('asd.docx')'==>href='javascript:openDocument(\'asd.docx\')'. Notice\'escaping