1

I have an issue with custom action.

Here is the definition of my custom action:

  <CustomAction
          Id="GoToDefi"
          Title="Go To"
          Description="Go To"
          RequireSiteAdministrator="FALSE"
          RegistrationType="ContentType"
          RegistrationId="0x01"
          GroupId="ActionsMenu"
          Location="DisplayFormToolbar"
          Sequence="1000">
    <UrlAction Url="javascript:GoToFunction();"/>
  </CustomAction>

So basically this is bound to CT and in display item form when i click on it, it doesnt redirect to anywhere, it just refereshes and that is it.

Here is the function code:

function GoToFunction()
{
    //Some extra steps are done

     window.location.href = "www.google.com";
}

Any idea what am i missing?

UPDATE:

I noticed a bit strange behaviour, when i hover over my link, i see that it has javascript:_dopstostback(...); But not my script.

When i do the debugging, my script is wel being called, but i think this _doPostBack overwrites my changes. I checkthed the html and i see following:

....
<tr>
<td class="ms-toolbar" nowrap="nowrap" >
   <a id="....toolbartbl_rpControls_ct112" href="javascript:_doPostBack('ct1000....','')"/>
   <a id="....toolbartbl_rptControls_CT112_LinkText" href="javascript:myfunction();" />
</td>

I don't know why but there are 2 anchor elemenets, and i think that postback is breaking my redirection.

But if in my custom action i give url like that url='www.google.com' then both of elements have href to www.google.com. But if i use any kind of javascript then it is not working anymore.

2 Answers 2

1

Are you using an older version of IE? Previously IE hade problems with redirecting with href. Try if this line of code works:

window.navigate("http://www.google.com");
3
  • No, this solution doesn't work either, and i tested and for example i can redirect to other page, if i use this call for example on document ready, but in the function it doesnt :(
    – Shkipper
    Feb 28, 2013 at 7:25
  • Can you see if your method is actually loaded at all? And maybee try som console.log() to see that the code line is actually executed Feb 28, 2013 at 7:29
  • yes, i noticed something strange, ill update my post in a sec
    – Shkipper
    Feb 28, 2013 at 8:22
0

how about removing the last part ;) :

function GoToFunction()
{
    //Some extra steps are done

     window.location = "www.google.com";
}

if it was 2010 it would of been easy ;) ,

try adding javascript:void so like this:

  <CustomAction
          Id="GoToDefi"
          Title="Go To"
          Description="Go To"
          RequireSiteAdministrator="FALSE"
          RegistrationType="ContentType"
          RegistrationId="0x01"
          GroupId="ActionsMenu"
          Location="DisplayFormToolbar"
          Sequence="1000">
    <UrlAction Url="javascript:void GoToFunction();"/>
  </CustomAction>
5
  • That's a valid answer, albeit not very informative as to why. window.location.href doesn't always work. Feb 27, 2013 at 19:26
  • i tried this also but it didn't work :)
    – Shkipper
    Feb 27, 2013 at 20:15
  • is this in 2010 or 2007?
    – Ali Jafer
    Feb 28, 2013 at 12:57
  • it is SharePoint 2007
    – Shkipper
    Mar 1, 2013 at 8:49
  • ammended my answer
    – Ali Jafer
    Mar 1, 2013 at 15:41

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.