Going Back and Refreshing Page

The page that one of my back button navigates to requires some JavaScript code to run to hide div until a button is pressed. Essentially, what I needed was to be able to go back while having the page I’m going back to reload. Unfortunately, simply using history.go(-1) takes me back a page but loads it from cache. I’m not sure if it’s the iPhone/Mobile Safari that I’m testing on, but none of the following meta tags worked:

<meta http-equiq="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<meta http-equiv="Cache-Control" content="no-cache">

So I scoured Google for a while until I stumbled upon a solution. There’s a call to get the URL of the last page. Then all I had to do was replace window.location with the URL.

var lastPage = document.referrer;
window.location.replace(lastPage);

Pretty basic, but it works if you need to go back and and refresh a page. No messing around with cache, cookies, sessions, what have you.

Zooming to 100% in Photoshop

I finally decided to poke around with different keyboard shortcuts to zoom to 100% in Photoshop since I seem to zoom in and out just about every other click (slight exaggeration).  I am proud to report that I successfully found it.  Not sure how common knowledge this is, but in case you didn’t already know, ctrl+1 zooms your image to 100%.  And similarly, ctrl+0 fits your image to the screen.  You could also double-click on the magnifying glass tool (zoom tool) to set the image to 100%, but I found the keyboard shortcut more efficient since I don’t have to slide the cursor all the way across the screen into that small little square icon.  You could also use the navigator and zoom in or out using the provided buttons on either side of the slider until you hit 100%.

Disable Horizontal Scrolling in iPhone Web App

I spent a couple of hours trying to figure out how to prevent my iPhone web app from allowing the user to drag and pan the screen horizontally (because it’s horribly tacky and annoying when the user accidentally drags their fingers left and right and sees the screen shift back and forth until it eases back into frame).  I had the right line in the HTML file, so I was really frustrated that it wouldn’t work, and was even more frustrated that hardly anyone else had the same problem I was having.  Turns out no one else was having the same problems because it’s somehow my fault.

So in conjunction with using:

<meta content="width=device-width, user-scalable=no" name="viewport" />

you have to be sure your body width is within the screen’s width (which is of course 320px in iPhones’ case).  For some reason, the scaling is off so adding width:320px into my body{} property in my CSS file didn’t work, so I had to use 302px instead. That’s pretty odd, but I guess it works.  I’m still kind of annoyed that the body needs the width to be specified.  Looking at other web app’s CSS, it looks like it works fine without having to specify the dimensions.  I’m not sure how my cheap fix will pan out when I work on the rotation detection, but I’m sure it’s some basic JavaScript to get the width inside the body property in the CSS and changing that.

Multiple jQuery Selection Dropdown Menus

To try and keep a consistent look of the mobile web app, I’ve implemented a jQuery Dropdown menu to be used in place of the generic HTML form select.  The problem with the particular menu I used was that by default, only one selection would be used as the parameter to be passed no matter how many menus on are put on the page (that is, each dropdown menu on the page are not independent of each other).  I used two “flat” style dropdowns, but I think this should work for any other style menus you use. After a few hours of being stumped, I finally realized that I could just write some if-statements to check which menu whatever is being selected is from. I did eventually get it to work the way I want it to–which is to have each dropdown menu’s selected item be a parameter to pass to the JSP.  Here’s what I did.

In my HTML file, I gave each of the dropdowns different named ids.

<a id="flat" class="fg-button fg-button-icon-right ui-widget ui-state-default ui-corner-all" tabindex="0" href="#suites">
//and
<a id="flat2" class="fg-button fg-button-icon-right ui-widget ui-state-default ui-corner-all" tabindex="0" href="#suites">

Then in fg.menu.js, I added some if statements to check which menu whatever was just selected belongs to, and then stored that to its own global variable.

var suiteParam;
var reourceParam;

this.chooseItem = function(item){
   menu.kill();
   if(&(item).attr('href').match('suiteNames')){
      suiteParam = '/status.jsp?suiteNames='+$(item).text();
   }
   if(&(item).attr('href').match('resourceIds')){
      resourceParam = '&resourceIds='+$(item).text();
   }
};

selected = function(){
   if(suiteParam==undefined || resourceParam==undefined){
      alert('Please select both a suite and resource');
   }
   if(suiteParam.indexOf('suiteNames=')>-1 && resourceParam.indexOf('resourceIds')>-1){
      window.location.replace.(suiteParam+resourceParam);
   }
};

You can find the menu I used at filamentgroup.com.

Detecting Mobile Safari in JSP

The mobile web app I’m creating at work requires two entirely separate versions (one for desktop browsers and one for Mobile Safari), so I came up with a fairly decent way of detecting whether the browser is being run on an iPhone.  There might be some typos in the code below since I typed it from my head, but this is the gist of it.  If you need to detect more mobile device browsers, you can just make an array of all the different user agent string (which can be found here) and do a string comparison against them all in a for-loop or something.

<%
String wholeUserAgentStr = request.getHeader(user-agent);
String mobilePlatformStr = "iPhone";
String userPlatform = wholeUserAgentStr.substring(wholeUserAgentStr.indexof("(")+1, wholeUserAgentStr.indexof(";"));

if(userPlatform.equals("iPhone")){
   //print mobile XSL file
} else {
   //print regular XSL file
}
%>

This works fine, but my boss tweaked it and made it into JSP 2.0 and created it as its own tag.  There’s more to it than this, but this line is pretty much what I came up with above, just in a much more concise manner.

<c:set var="xsltFile" value="{$fn:indexOf(header['user-agent'], 'iPhone') < 0 ? xsltFile : mobileXsltFile}" />

The Exciting World of Typography

A thread regarding typography showed up in my Google Reader from IxDA.  A reply post provided a link to a very helpful website that talks about typography online called The Elements of Typographic Style Applied to the Web.

I briefly read through two pages last night and found it really informative.  I think I finally completely understand what “ems” are and how to use them.

Conforming to an Existing Design

I’m a little stuck in a design/layout problem at work.  Up until now, I’ve had no problems translating the full desktop browser version of the data into an iPhone web app layout.  But I’m currently at a section of data where I’m unsure how I should apply my theme that I’ve been using with the rest of the data.  My existing “theme” consists of basic white boxes with rounded corners with the right side of each box showing the line of information, and the left side describing the information to the right.  But now the section of data I’m working on has four links and a single line of code wrapped in pre-tags.  I’m a little unsure how I should tweak my white-box theme to accommodate this irregular bit of data without having to re-change the rest of the pages.

I considered this problem when I was sketching out some crude wireframes for the app, but overlooked this because this section is merely a fraction of all the other data that actual conforms to my layout.  It didn’t seem like too much of a problem at the time when I ignored it because it seemed like a relatively easy problem to solve, and I had to start producing something aside from sketches.  But now thinking this through, most of what I’ve come up with makes it stick out from the rest of the pages.  I’m sure all I’m missing is some ingenuity.  I just need to stick four links, a line of code, and a title into a white box with it making sense and not ruining the rest of the pages.  No big deal.

Indecisive?

I finally mustered up the brain power and made that yes/no decider I’ve been thinking about making for a while now.  I tried a couple of weeks ago at midnight, but drew a blank and couldn’t remember how to program.  It took me about 40 minutes to get the basic application to work, then maybe another 20 minutes to work out some kinks and polish it off.  I should’ve spent more time on a more clever title, but I figured since the program was made to be simple and straightforward, it doesn’t hurt that the title reflects it too.

Yes_No screenshot

Head over to my download page and get a copy.

Hello world!

Here’s my traditional first post.  More to come, of course.