-1

I want to save some JavaScript code as a bookmark in chrome so it automatically opens my university login site and clicks on on the login button. I am completely inexperienced in JavaScript, so I have no clue how to do this. I snipped together the following code, which opens the correct website, but then does not click on anything. The first URL automatically puts me to the login site (third URL in the code) in case I have not logged in yet in this window.

(function() {
    window.location.replace("https://lms.uzh.ch/auth/MyCoursesSite/0");
    window.onload = function(){
        if (current_url.startswith('https://lms.uzh.ch/auth/MyCoursesSite/0')) {
            return;
        }
        if (current_url.startsWith('https://lms.uzh.ch/dmz/')) {
            document.getElementById("wayf_submit_button").click();
        }
    };
})();

I'm sorry if this is too obvious a question and annoys any experts but as I said I am a complete beginner. I would of course add the "javascript:" at the beginning for chrome to understand the bookmark.

unrealapex
  • 578
  • 9
  • 23

1 Answers1

0

When you use window.location.replace, you change the address and you code can't work anymore.

I can suggest using some browser extension, your "click function" should work then.

I guess you could also try to make some simple html page with iframe, you call your "click function" at this page, but you target it to the iframe. After that you can change browser's location to the university's webpage as you should already be logged in.

<html>
 <head>
 </head>
 <body>
  <iframe src="your_university_address.com" id="some_id" onload="click_button()"></iframe>
  <script>
   function click_button()
   {
    my_iframe=document.getElementById('some_id');
    my_iframe.contentDocument.getElementById('your_button_id').click();
   }
  </script>
 </body>
</html>

Very simple but it should do that job. (You can achieve similar result by using window.open() I guess)

Michal Moc
  • 36
  • 4