Weird Thoughts From Eric's Head

Tags - Categories : All | AJAX | BUSINESS | PERSONAL | PROGRAMMING | BOOK REVIEW

String Theory
A string walks into a bar with a few friends and orders a beer. The bartender says, "I'm sorry, but we don't serve strings here." The string walks away a little upset and sits down with his friends. A few minutes later he goes back to the bar and orders a beer. The bartender, looking a little exasperated, says, "I'm sorry, we don't serve strings here."

So the string goes back to his table. Then he gets an idea. He ties himself in a loop and messes up the top of his hair. Then he walks back up to the bar and orders a beer.

The bartender squints at him and says, "Hey, aren't you a string?"

And the string says, "Nope, I'm a frayed knot."

about:blank and secure sites
Sometimes when you get a script that writes new content to the window, they use var winPop = window.open("about:blank"); and it works all find and dandy on a regular http site. The common question I get is: "I have seen this work on my development server. I have a calendar function that uses about:blank, but when I run it on my secure site (https) it fails."

Well it is true, the secure setting throws a security warning when this happens. This is just one of those annoying security warnings you need to live with. Now lets look at what about:blank is. If you were to do a view source, you would see it is just two html tags. The opening html tag and the closing html tag.

Now what I tell people to do is create the same thing and name it myblank.html. Now add this file name where your function calls the about:blank and you should see your code should run. I have seen instances where this has not worked, but in 99% of the cases it does the job.

If you have other solutions, please tell me!

Eric Pascarello
Moderator of HTML/JavaScript at www.JavaRanch.com
Author of: JavaScript: Your Visual Blueprint for Dynamic Web Pages

One handed
Why did the man with one hand cross the road?

To get to the second hand shop.

Cursor:hand not working
Another question I see posted is how come by cursor changes to the hand with IE but not with Mozilla.

Your code most likely looks like: cursor: hand;

The reason is IE supports the keyword hand and mozilla, netscape, firefox do not.

You want to use cursor: pointer; to work on all the browsers.

Eric Pascarello
Moderator of HTML/JavaScript at www.JavaRanch.com
Author of: JavaScript: Your Visual Blueprint for Dynamic Web Pages

Easy Password
A six-year-old girl sneaked up behind her father. Then she turned and ran into the kitchen, squealing to the rest of the family, "I know Daddy's password! I know Daddy's password!"

"What is it? her sisters asked eagerly.

Proudly she replied, "star, star, star, star, star, star!"

Minimum Size For PopUp window
I have seen people ask this question a couple of times within the past couple of weeks. A pop up window does have a minimum size, the reason for this is to keep people from opening up windows that are too small to use.

The smallest size that you can make a pop up window is about 100 pixels by 100 pixels. It may differ from browser to browser.

The same size restriction applies to window.resizeTo(100,100)

Eric Pascarello
Moderator of HTML/JavaScript at www.JavaRanch.com
Author of: JavaScript: Your Visual Blueprint for Dynamic Web Pages

Another Blonde Joke
A manager walks into his office and sees a blonde crying. He approaches her and asks why she's crying. She tells him she just found out her mother died. The manager tells her to go to take the rest of the day off and not to worry about work. Later, the manager calls the blonde to see how she's doing. The blonde is crying harder than before. He tries to console her, but he couldn't. The blonde says, "I was calling everyone to let them know about my mother's death and I found out something horrible." "What?" the manager replied. "I found out my sister''s mom died too!"

Chat Room Software
The other day I was doing my normal rounds on all of the forums I post on regularly. I came across a post on a chat room that was based on JavaScript and PHP.

The site is: http://www.qwadchat.com

I was quite impressed on how quick the response time was and how smooth it was working. The program is still in beta, but it is worth checking out if you want to add a small chat room to your web site.

I have suggested to the developer to make an option to allow for UBB-type of mark-up so it is more secure. The HTML mode is allowed and blocks all of the troublesome JavaScript events that could cause problems. BUT it still allows for HTML markup that can have BIG text in the display.

There is a demo room there and I hope you try playing with it. As time goes on it can only get better and the developer is planning to add more options that should make it easier to use.

Eric Pascarello
Moderator of HTML/JavaScript at www.JavaRanch.com
Author of: JavaScript: Your Visual Blueprint for Dynamic Web Pages

Gates Joke for a Gates' story
Bill Gates meets Hugh Grant at a Hollywood party. They are talking and Bill says: "I've seen some great pictures of Divine Brown lately, I sure would like to get together with her!"

Hugh replies: "Well Bill, you know ever since our incident, her price has skyrocketed, she's charging a small fortune."

Bill: "Hugh, money's no object to me. What's her number." So, Hugh gives Bill her number and Bill sets up a date.

They meet & after they finish, Bill is lying there in ecstasy, mumbling "God...now I know why you chose the name Divine."

To which she replies: "Thank you, Bill.....and now I know how you chose the name ..... Microsoft."

IE7? Released proposed for this summer
I am sure you have seen this, but in case you have not. Gates has said they are going to ship IE7 seperate from Loghorn.

Read More Here

Eric Pascarello
Moderator of HTML/JavaScript at www.JavaRanch.com
Author of: JavaScript: Your Visual Blueprint for Dynamic Web Pages

The Proxy Father
The Smiths had no children and decided to use a proxy father to start their family. On the day the proxy father was to arrive, Mr. Smith kissed his wife and said, "I'm off. The man should be here soon." Half an hour later, just by chance, a door-to-door baby photographer rang the doorbell, hoping to make a sale. "Good morning, madam. You don't know me but I've come to...."

"Oh, no need to explain. I've been expecting you," Mrs. Smith cut in.

"Really ?" the photographer asked. "Well, good! I've made a specialty of babies."

"That's what my husband and I had hoped. Please come in and have a seat. Just where do we start?" asked Mrs. Smith, blushing.

"Leave everything to me. I usually try two in the bathtub, one on the couch and perhaps a couple on the bed. Sometimes the living room floor is fun too; you can really spread out."

"Bathtub, living room floor? No wonder it didn't work for Harry and me."

"Well, madam, none of us can guarantee a good one every time. But if we try several different positions and I shoot from six or seven angles, I'm sure you'll be pleased with the results."

"I hope we can get this over with quickly," gasped Mrs. Smith.

"Madam, in my line of work, a man must take his time. I'd love to be in and out in five minutes, but you'd be disappointed with that, I'm sure."

"Don't I know!" Mrs. Smith exclaimed. The photographer opened his briefcase and pulled out a portfolio of his baby pictures. "This was done on the top of a bus in downtown London."

"Oh my god!!", Mrs. Smith exclaimed, tugging at her handkerchief.

"And these twins turned out exceptionally well when you consider their mother was so difficult to work with." The photographer handed Mrs. Smith the picture. "She was difficult ?" asked Mrs. Smith. "Yes, I'm afraid so. I finally had to take her to Hyde Park to get the job done right. People were crowding around four and five deep, pushing to get a good look."

"Four and five deep?" asked Mrs. Smith, eyes widened in amazement.

"Yes," the photographer said.

"And for more than three hours too. The mother was constantly squealing and yelling. I could hardly concentrate. Then darkness approached and I began to rush my shots. Finally, when the squirrels began nibbling on my equipment, I just packed it all in." Mrs. Smith leaned forward.

"You mean they actually chewed on your, eh......equipment ?"

"That's right. Well madam, if you're ready, I'll set up my tripod so that we can get to work."

"Tripod??", Mrs. Smith looked extremely worried now.

"Oh yes, I have to use a tripod to rest my Canon on. It's much too big for me to hold while I'm getting ready for action. Madam ? Madam?..... Good Lord, she's fainted!"

Force Window Min Size
Well I normally do not like to talk about things that I can not stand to find on a webpage, but I guess there are times when this can be useful. A post here on the JavaRanch forums asked to not allow the window to go under a certain size. Well at first it looks rather easy. Detect the window size and resize it. You will fire it onload and onresize. Well lets start out basic. Lets force a window to always be a certain size. For instance make the window 400px X 400px. This is just like opening up a pop up window with the resize ability set to false.

function SetSize(){
  window.resizeTo(400,400);
}
Now you can call the function with the body tag
<body onload="SetSize()" onresize="SetSize()">
So now you have the window set to a size, but we want to force it to only resize if the window is smaller then a minimum size. First thing we need to do is set some minimum sizes
var minW = 400;
var minH = 400;
Now we need to create a function to grab the width and height of the current browser. Now there are if statements in this, if you want to know why you need them, look on page 262 of my book since it explains it and I am too lazy right now! The only difference between this code and the one in the book is I am returning the width and height values separately.
function getPageWH(xPart){  
  if( typeof window.innerWidth  == 'number' ) {
    pageW = window.innerWidth;
    pageH = window.innerHeight;
  } 
  else if(document.documentElement && 
    document.documentElement.clientWidth ) {
    pageW = document.documentElement.clientWidth;
    pageH = document.documentElement.clientHeight;
  } 
  else{
    pageW = document.body.clientWidth;
    pageH = document.body.clientHeight;
  }
  if(xPart=="w")return pageW;
  else return pageH
}
Now we need to create a function that resizes the window. The first part we are looking at determines with the window is smaller then out defined values. If they are, it triggers a flag that says the window needs to be resized.
function VerifySize(){
  var resizeMe = false;
  var winW = parseInt(getPageWH("w"));
  var winH = parseInt(getPageWH("h"));
  if(minW>winW){winW=minW;resizeMe=true;}
  if(minH>winH){winH=minH;resizeMe=true;}
The next part of the code resizes the window if the flag has been flipped.
  if(resizeMe){
    window.resizeTo(winW,winH);
Now most people would think that the line above is fine, but that is not the case. If we left it like this, the window would continually resize. until it hit our minimum dimension of 400X400. The reason is because when you resize the window, it includes the chrome (part of the window that contains the statusbar,titlebar, etc.) On the other hand, the getPageWH function returns the space available to your web page to use. In does not account of the toolbars. So now we need to account for it.

It is rather easy to do this. We just need to grab the new width and height of the window and find the difference from the values we are looking at. Apply the difference and you have the set size you were after.
    var winW2 = winW - parseInt(getPageWH("w"));
    var winH2 = winH - parseInt(getPageWH("h"));
    window.resizeTo(winW + winW2,winH + winH2);
  }
}
Below is a basic example all put together:
<html>
  <head>
    <script type="text/javascript">
      var minW = 400;
      var minH = 400;
 
      function getPageWH(xPart){  
          if( typeof window.innerWidth  == 'number' ) {
            pageW = window.innerWidth;
            pageH = window.innerHeight;
          } 
          else if(document.documentElement && 
                     document.documentElement.clientWidth ) {
            pageW = document.documentElement.clientWidth;
            pageH = document.documentElement.clientHeight;
          } 
          else{
            pageW = document.body.clientWidth;
            pageH = document.body.clientHeight;
          }
          if(xPart=="w")return pageW;
          else return pageH
        }
 
 
        function VerifySize(){
          var resizeMe = false;
          var winW = parseInt(getPageWH("w"));
          var winH = parseInt(getPageWH("h"));
          if(minW>winW){winW=minW;resizeMe=true;}
          if(minH>winH){winH=minH;resizeMe=true;}
 
          if(resizeMe){
            window.resizeTo(winW,winH);
            var winW2 = winW - parseInt(getPageWH("w"));
            var winH2 = winH - parseInt(getPageWH("h"));
            window.resizeTo(winW + winW2,winH + winH2);
          }
          document.getElementById("blah").innerHTML = "(" + parseInt(getPageWH("w")) + "," + parseInt(getPageWH("h")) + ")";
 
        }
      </script>
  </head>
  <body onload="VerifySize()" onresize="VerifySize()">
    <div id="blah"></div>
  </body>
</html>  
Now for the part I always love to say. Browser's do have the ability to block the auto-resizing of web pages. Do not force this on a user, a lot of people will not go back to a site that controls there browser. Also JavaScript can be disabled!

Eric Pascarello
Moderator of HTML/JavaScript at www.JavaRanch.com
Author of: JavaScript: Your Visual Blueprint for Dynamic Web Pages