Note that there are some explanatory texts on larger screens.

plurals
  1. POjavascript oo programming syntax help for a noob
    primarykey
    data
    text
    <p>I'm making my first stab at writing some oo style js. When my page loads, it's executing my login() function twice and the event listener that I want to fire the login() isn't working at all. Any help would be greatly appreciated. Here is my code:</p> <pre><code>(function( window, undefined ) { var document = window.document, navigator = window.navigator, location = window.location; //build the login button var DA = { width : '70px', height : '20px', createLoginButton : function(){ var a = document.createElement('a'); a.style.width = this.width; a.style.height = this.height; a.style.cursor = 'pointer'; var div = document.createElement('div'); div.id = 'da_login_button'; div.onclick = DA.login(); div.innerHTML = "client login"; div.style.width = this.width; div.style.height = this.height; div.style.backgroundColor = '#59724A'; div.style.color = 'white'; div.style.border = '4px solid #6B5D49'; div.style.padding = '3px'; div.style.textAlign = 'center'; a.appendChild(div); return a; }, //write the button to the dom writeLoginButton : function(){ var dest = document.getElementById('digital_arborist_login'); dest.style.width = this.width; dest.style.height = this.height; var theButton = DA.createLoginButton(); dest.appendChild( theButton ); theButton.addEventListener("click", DA.login(), false); }, //detect ssl isSecure : function(){ if (location.protocol === 'https:') { return true; } else { return false; } }, // the login function login : function(){ alert('href: '+location.href+'&lt;br /&gt;protocol: '+location.protocol); }, }; window.DA = DA; })( window ) // start the magic DA.writeLoginButton(); </code></pre> <p><a href="https://www.austintreeexperts.com/services/service_area.cfm" rel="nofollow">Here is the web page where I'm testing my code.</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload