-3

I would like to run the following code but only if the condition is that the url contains "Mode=edit" somewhere. (If I run it on every page it gives error).

<script language='javascript'>
    function Save() {
        __doPostBack('ctl00$MainContentPlaceHolder$btnSave', '');
    }

    function Redirect() {
        window.location = "SessionTimeout.aspx"
    }
    window.onload = function () {
        setTimeout(Save,15000);
    }
</script>

How can I have it check for that portion in the url and only then run this script above?

Yevgen
  • 767
  • 2
  • 9
  • 22

1 Answers1

2

Just add an if statement that checks if document.location contains the string.

if (document.location.href.indexOf('Mode=edit') > -1){ 
    //Your code goes here
}
Banana
  • 7,424
  • 3
  • 22
  • 43
HaukurHaf
  • 13,522
  • 5
  • 44
  • 59