SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool Removing Inline Scripts From Body Element

    Back in the Bad Old Days I had a body element that liked like this:
    <body onLoad="startNav();testingWatermark();opener.opener = top; opener.close()" onsubmit="showClock();" oncontextmenu="return true;">

    Now, wanting to be a hip, web 2.0 developer, I removed as much as I could from the body. It now looks like this: <body>. Yay me. Unfortunately, I seem to have lost some functionality at the same time. I wrote a script to try and do the same thing as the previous incarnation of body.
    Code:
    	function startScripts() {
    		startNav();
    		testingWatermark();
    		clockMe();
    		document.onkeydown = keyDown; // doesn't work
    		document.forms[0].onsubmit = showClock; // doesn't work
    		window.oncontextmenu = return false; // doesn't work
    		opener.opener = top;  // doesn't work
    		opener.close() // doesn't work
    	}
    		
    	window.onload = startScripts;
    Just so you know what the called functions are (they worked when in the body element):
    Code:
        function keyDown() {
            var keycode = event.keyCode;
            if (keycode == "120") {
                if(document.getElementById("calculate").disabled) {
                    alert("Can not calculate, model is not changed!");
                    return;
                }
                
                disableCalculate();
                submitCalculate();
            }
        }
    and
    Code:
    function showClock() {
    	try {
    		var style2 = document.getElementById('cover').style;
    		style2.display = style2.display? "":"block";
    	}
    	catch(e) {
    	}
    }
    Help me, Obi-Wan Kenobi. You're my only hope.

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try changing window.oncontextmenu to document.oncontextmenu.

    Why did you write keyDown in such a way that it requires support for IE's non-standard event model?

    Why did you use a try/catch in showClock?

    For the rest, we'll probably need to see more of your code to be able to help you.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kravvitz View Post
    Why did you write keyDown in such a way that it requires support for IE's non-standard event model?
    It's an internal app and our users only have access to IE6. And I didn't write it.

    Quote Originally Posted by Kravvitz View Post
    Why did you use a try/catch in showClock?
    I didn't add that. It was originally only supposed to be a simple script to flip a switch. If I had to guess, it was because another developer wanted a way to be able to turn it off.

    The other stuff I really want is closing the opener window.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •