Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

redirect();
</script>
share|improve this question
add comment

2 Answers

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?

HTH

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
add comment

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) {
        oldonload();
      }
      func();
    }
  }
}
addLoadEvent(myFunction1);
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
add comment

Your Answer

 
discard

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.