0

When opening a SharePoint 2010 form in modal mode I get the following error:

Uncaught TypeError: Cannot read properties of undefined (reading 'href')

See code below for usage and troubleshooting.

$(document).ready(function () {
  ExecuteOrDelayUntilScriptLoaded(OnLoad, "sp.js");
  function OnLoad() {

      var id = GetUrlKeyValue("ID", false, location.href); <== Error
      createCookie("Parent", id); // Create cookie

  } // End onload
}); // End document ready

I'm not sure what happened yesterday, but this has been working for years in other projects in SP, but for this particular project just popped up this error.

3
  • 1
    Which browser & version are you using? Try using window.location.href. Let me know if it works. Jun 24, 2022 at 4:25
  • Ganesh, this worked perfectly. Thank you.
    – Ghoztrider
    Sep 7, 2022 at 12:09
  • Great, glad it worked for you. I have added the same as an answer below. Sep 7, 2022 at 12:14

1 Answer 1

2

Use window.location.href instead of location.href like:

$(document).ready(function () {
  ExecuteOrDelayUntilScriptLoaded(OnLoad, "sp.js");
  function OnLoad() {

      var id = GetUrlKeyValue("ID", false, window.location.href); 
      createCookie("Parent", id); // Create cookie

  } // End onload
}); // End document ready

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.