Tech Musings

Saturday, November 25, 2006

Tab Locking in Firefox

I was forced to deal with odd behavior exhibited by Firefox today that drove me crazy for almost an hour. I used Apple's iWeb to post some pictures and a short movie of our Thanksgiving turkey day, but when testing my iWeb slide show after publication I kept receiving a 404 error for a phantom page that wasn't being found on my server. I finally traced the problem to iWeb's generated javascript which utilizes a void operator. Ultimately, the problem was related to how I had my tab browsing preferences set in Firefox. I enabled the "Tab Locking" feature to "Force all left-clicked links to open in new tabs." The javascript void used in the iWeb slide show was instructing the browser to evaluate some type of expression javascript:void GetNextImage() but do nothing with it, but Firefox WAS attempting to do something with the expression including forcing open a new window and searching for a null page. The iWeb photo slide show no longer attempted to open these phantom pop-up pages after I disabled the tab locking option.

Monday, November 20, 2006

Refresh on Form Update

I finally managed to create a workaround to address a recurring problem I've been having using the php header ("Location:") function to refresh an admin page after updating a record using a form submission. The purpose of the workaround was to create an auto refresh on the visions admin page that would display a record's updated data in a drop-down field after the record was modified. This would alleviate the need for the user to manually reload the page to see the changes. I've successfully used the PHP header function to refresh a page after an update from time to time, but it wasn't working correctly in this particular case. In fact, the server was throwing the dreaded "Cannot modify header information - headers already sent" complaint that annoys the absolute bejeezzes out of me. My first attempt to address the issue was to turn output buffering "ON" in my php.ini file, but this caused another headache with dynamic GD image thumbnail creation on my photo gallery admin catalog page; I needed to find another solution. After racking my brain for a few hours I ended up using a combination of a META "Refresh" directive to temporarily jump away from the admin page to a secondary page, and then a javascript onLoad event in the second page to redirect back and force the admin page to reload itself and display the updated information in the drop-down menu. The trickiest part was passing the user ID variable from the first page to the second page and then back to the first page.

>>>FIRST PHP PAGE >>>

if form is submitted...

$tid = $_POST['tid']; //Get the ID

update the information...
on success ...

echo '<~META HTTP-EQUIV="Refresh" Content="0; URL=refresh.php?tid='.$tid.'"~>';
die;


>>>SECONDARY REFRESH PAGE >>>


<~ head ~>

function goToURL() {
var url = null;
url = "visions_modify.php?tid=";
url += "";
window.location = url; }

<~ /head ~>

<~ body onload="goToURL();" ~>

processing...


<~ /body ~>
<~ /html ~>

UPDATE (6/26/07)
I was having difficulty today with the visions modify pages (lcd and comp) fields not refreshing properly on update and holding entered data; the data wasn't sticking and wouldn't display until a second browser refresh was performed. I implemented the fix above but it didn't work until I added the following code to the top of the page. I'm not sure WHY I needed to add this code, but I don't have time to figure it out at the moment. Perhaps I will research this at a later time when I'm lessed swamped.

<--?php
$redirect = $_SERVER['HTTP_REFERER'];
session_register("redirect");
?-->

will also work if the following header is used:

<--?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past ?-->