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.CommentedJun 24, 2022 at 4:25
  • Ganesh, this worked perfectly. Thank you.CommentedSep 7, 2022 at 12:09
  • Great, glad it worked for you. I have added the same as an answer below.CommentedSep 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 

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.