-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
  • 737
  • 2
  • 9
  • 21

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,380
  • 3
  • 21
  • 42
HaukurHaf
  • 12,968
  • 5
  • 40
  • 56