I have the following javascript in the NewForm.aspx. It works but opens the link in the NewForm.apsx. I need to open the link in the parent window where NewForm.aspx was initiated from. What am I doing wrong?

<script type="text/javascript">
function redirect()
  var inputcCtrls = document.getElementsByTagName("input");
  for(m=0; m<inputcCtrls.length; m++)
       if(inputcCtrls[m].type == 'button' && inputcCtrls[m].value == 'Finish')
               var funcOnClick = inputcCtrls[m].onclick;
               inputcCtrls[m].onclick = function () {  window.close(); window.location = "http://www.google.com"; };


2 Answers 2


I haven't worked with windows in Javascript for a while, but I think there's a window.parent you can access? Possibly set that URL first then close this window?


  • This works but it broke the addition to Survey List. inputcCtrls[m].onclick = function () { window.parent.location = "surveys/Pages/SurveyWirelessThankYou.aspx"; window.close();}; Aug 18, 2011 at 18:56
  • I'm not sure I follow, so it works but it's broken? Aug 18, 2011 at 19:38
  • Javascript redirects to parent page. However, adding new item to the survey list does not work anymore. Aug 18, 2011 at 19:52
  • I think I am overwritting and intended onclick function for "Finish" button. I may want to add to existing funcion. How do I tell java that let it do it's native job and additional functionality to the "Finish" button. Aug 18, 2011 at 20:06
  • That i'm not sure on, you may want to repost in a javascript group Aug 18, 2011 at 20:40

From the code side this should work:

self.opener.location = "http://www.google.com";

As you have discovered when you start using javascript events in SharePoint things can get a little funky. This is called event HiJacking. I found this solution, but it only applies to the OnLoad event. You may be able to modify it to fit your needs for OnCLick.

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
  • Actually, onclick has to run it's intended function (in this case, submit the survey which creates record in the survey list). How do I let the onclick run it's original function and add additional function? Aug 19, 2011 at 14:13
  • How are you adding onClick? Through jQuery? Aug 19, 2011 at 23:42

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.