I have a script that I am using to alert the user before they submit the form. It also is scripted to redirect the page upon being submitted. These functions seem to work properly, all except the strange thing that it causes in the background. Whenever I have this script installed as a web part, I am not able to access the Web Part editor. As soon as I delete it, I can access it again. Can anyone offer any advice?

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script><script type="text/javascript">
(function(w) {
  w.PreSaveAction = function() {
    return w.confirm('Please make sure to select Approve or Reject next to your name.');
  var source = 'https://mysite/sites/hhc/forms/apinvoice/SitePages/form_closed.aspx'
  var loc = w.location;
  var s = loc.search;
  if (s.indexOf(source) >= 0) return;

  loc.href = loc.href.replace(/\?.*/, '') + '?' + s.replace(/\?/, '').split('&').filter(function(q) { 
    return !q.match(/^source/i); 
  }).join('&') + '&Source=' + source;

Why not just use:

function PreSaveAction()
  • 2
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review – Mike Jun 6 '17 at 0:33
  • It will work... and the mobile app will not allow me to leave such a response as a comment, which is really the reason I left it as an answer instead of a comment. I tried leaving it as a comment in the mobile app and coole not, so allow a full editing experience for comments and next time I will do that... – mannaggia Jun 6 '17 at 10:35
  • @mannaggia - Thanks for your feedback. I found this script and tried it out, and it worked, but caused that strange issue with the Web Part Editor. I am not JavaScript savy at all, so would you mind explaining more about what I could try or could leave out in the script above? – cbbrown Jun 6 '17 at 12:41
  • @cbbrown What issue it caused? – Hursh Gupta Jun 6 '17 at 12:50
  • When I go to open the "Edit Web Part" panel, it will not open. If you can imagine how pop up blocker blocks something from opening on a browser and remains on a page, that's how it looks. – cbbrown Jun 6 '17 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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