SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 = ""; };

share|improve this question

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?


share|improve this answer
This works but it broke the addition to Survey List. inputcCtrls[m].onclick = function () { window.parent.location = "surveys/Pages/SurveyWirelessThankYou.aspx"; window.close();}; – Nancy o'Donnell Aug 18 '11 at 18:56
I'm not sure I follow, so it works but it's broken? – David Lozzi Aug 18 '11 at 19:38
Javascript redirects to parent page. However, adding new item to the survey list does not work anymore. – Nancy o'Donnell Aug 18 '11 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. – Nancy o'Donnell Aug 18 '11 at 20:06
That i'm not sure on, you may want to repost in a javascript group – David Lozzi Aug 18 '11 at 20:40

From the code side this should work:

self.opener.location = "";

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) {
share|improve this answer
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? – Nancy o'Donnell Aug 19 '11 at 14:13
How are you adding onClick? Through jQuery? – Abe Miessler Aug 19 '11 at 23:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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