0

When I place html a tag or some javascript in code snippet/content editor, the function is working fine. But when I want to apply this button to all pages and inserted it in the sharepoint 2013 HTML file associated with the master, the hyperlink text is rendering but not the modal pop-up box.

<input 
    onclick="javascript:SP.UI.ModalDialog.showModalDialog({ 
        url: 'example.com', 
        title: 'Feedback Form' 
    }); 
    return false;" 
    id="btnVote" 
    type="submit" 
    style="color:blue;text-align: left;font-size: 14px; cursor: pointer;height:30px; width:195px;background: transparent;border: none !important;" 
    value="Get Support/submit feedback"
>

Both these codes are working in the content editor or script editor. Please help me. I have seen some posts saying I have to manually reference the runtime js files. As I am new to sharepoint 2013 detailed explanation would be appreciated.

2
  • "Both these codes are working in the content editor or script editor. " So what's your issue?
    – Keerthi
    Jul 28, 2015 at 13:49
  • The Issue is when I add this script in the masterpage, I can see the link text. But when I click on it nothing is happening.
    – sudheer ch
    Jul 28, 2015 at 14:20

4 Answers 4

1

Add these scripts to your masterpage:

<script  type="text/javascript" src="/_layouts/sp.core.js"></script>
<script  type="text/javascript" src="/_layouts/sp.runtime.js"></script>
<script  type="text/javascript" src="/_layouts/sp.js"></script>
4
  • Thanks for the reply. I added the above script.It still doesnot work. I know this is a dumb question but do I need to download all those .js files,upload and give the path?
    – sudheer ch
    Jul 28, 2015 at 14:33
  • You need not download those
    – Keerthi
    Jul 28, 2015 at 14:36
  • @sudheerch Make sure that the above scripts are loaded before/above your hyperlink. The error you're getting is likely because the SharePoint dependencies required for launching a Modal Dialog have not yet loaded. Do you see any errors in your browser's console (developer tools)? Jul 29, 2015 at 1:57
  • @jasonscript I have tried to add the above script in the header and also tried in body before my modal pop-up script, both scenarios don,t work.
    – sudheer ch
    Jul 29, 2015 at 6:16
0

The reason why the javascript it not called is as it is unable to get the system js files that are required. Include the following javascripts in the same sequence as mentioned and check.

<script src="/_layouts/1033/init.js" type="text/javascript"></script>
<script src="/_layouts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/_layouts/sp.core.js" type="text/javascript"></script>
<script src="/_layouts/sp.runtime.js" type="text/javascript"></script>
<script src="/_layouts/sp.js" type="text/javascript"></script
0

Use OpenPopUpPageWithTitle('example.com',function(){},null,null,'title') instead of SP.UI.ModalDialog.showModalDialog

It will take care of loading the required JS and opens the dialog

7
  • I have also used the above function. Its still not loading. <a href="javascript:OpenPopUpPage('test link');">Get Support/Submitfeedback</a>
    – sudheer ch
    Jul 29, 2015 at 14:55
  • did you get any error message in browser console when you clicked on the link? Jul 29, 2015 at 23:33
  • did you inspect the element and see the href attribute value is valid. I mean the double / single quotes rendered correctly? Jul 29, 2015 at 23:46
  • yeah the href is valid since Its working fine in the content editor webpart how it has to be. In the browser I am seeing "SCRIPT1015 : unterminated string constant". But I don't see any error in the script.
    – sudheer ch
    Jul 30, 2015 at 18:00
  • That means something is wrong with your href attribute. Can you copy paste the rendered markup by inspecting the element in dev tools. And also try to type javascript:OpenPopUpPage('/') in your browser address bar and hit enter. Make sure you type javascript: copy paste will ignore this in address bar Jul 30, 2015 at 18:15
0

The trick is to put the code in this

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {/*code here*/});

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.