Author Topic: Can you modify HTML attributes on the fly?  (Read 12929 times)

0 Members and 1 Guest are viewing this topic.

Offline mikejeep

  • Member
  • *
  • Posts: 29
Can you modify HTML attributes on the fly?
« on: November 21, 2006, 02:18:55 AM »
Does anyone know if it is possible to change HTML attributes when a page is loaded, perhaps by using some PHP or JavaScript?   I am trying to work out a hack to have the ALT attribute copied to the TITLE attribute, so all browsers can display tooltips -- specifically on the VWS-generated mesomap.  In essence, if an image has an ALT attribute, this script would copy that data to a TITLE attribute for the same image.

(Background: the "ALT" tag has long been used to have text display when the mouse pointer is moved over an image; unfortunately, this only works in Internet Explorer because it is 'illegal' if you read the HTML spec literally, so Firefox and other browsers ignore it.  The 'correct' method is to use the TITLE attribute instead)

I think something called a "postprocessor" is what I am looking for... I am not a very experienced programmer but if someone can lead me in the right direction, I can usually figure things out. :)

Thanks,
-Mike

Offline carterlake

  • Senior Contributor
  • ****
  • Posts: 243
    • CarterLake.org
Re: Can you modify HTML attributes on the fly?
« Reply #1 on: November 21, 2006, 08:00:56 AM »
Where do the alt tags for the mesomap come from? Are they "tags" you can generate to a file?

Without some source data to work with, I would imagine you'd have to create a page and have a complex PHP script go through and glean the ALT tags and then re-output the entire page with TITLE added to it.

The easiest suggestion would be to get the VWS developer to make the tags cross-platform compatible... but of course, I see your problem there.  :roll:

Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio

Offline up10ad N9RJH

  • USA Weather Finder
  • WxElement panel
  • Forecaster
  • *****
  • Posts: 578
  • Station will be back up someday...
    • Forecaster without a site
Re: Can you modify HTML attributes on the fly?
« Reply #2 on: November 21, 2006, 08:08:20 AM »
Mike,  I don't have an immediate solution, but I'm going to monitor this thread in hopes of an easy fix posted by someone else.  This problem has been mentioned many times before and the easy fix is to have Ed change the code to comply with the spec.  I just posted a request in the VWS bug report form in hopes that it makes it into a future release:
Quote
The mesomap links mouseover feature to display weather details of a location uses the ALT tag and does not work with browsers other than IE.  The TITLE tag also needs to have the information per the HTML spec.
Rick (N9RJH)
Have you joined USAWeatherFinder.com yet?

Offline weatheroz

  • Senior Contributor
  • ****
  • Posts: 216
    • http://www.jimboombaweather.com
Re: Can you modify HTML attributes on the fly?
« Reply #3 on: November 21, 2006, 08:21:08 AM »
Quote from: "carterlake"
Where do the alt tags for the mesomap come from? Are they "tags" you can generate to a file?

Without some source data to work with, I would imagine you'd have to create a page and have a complex PHP script go through and glean the ALT tags and then re-output the entire page with TITLE added to it.

The easiest suggestion would be to get the VWS developer to make the tags cross-platform compatible... but of course, I see your problem there.  :roll:


Sheesh, what do you expect... a miracle ??? :)

That's so damn ancient that request to fix up that issue, it was even ancient back when first starting looking at Weather Display, and that's nearly 2 years ago !!!

I've heard rumours that he finally made an attempt to fix up the FTP bug, albeit many years too late for many, so perhaps there's still a remote chance he'll get around to looking at ALT versus TITLE issue.... well just so long as his 'business partners' at WU don't get him to add some new feature. :)  :P
Brendan,
vk4blp
IRLP 6857 Echolink 672767


Offline weatheroz

  • Senior Contributor
  • ****
  • Posts: 216
    • http://www.jimboombaweather.com
Re: Can you modify HTML attributes on the fly?
« Reply #4 on: November 21, 2006, 08:25:59 AM »
Quote from: "k6dyc"
Mike,  I don't have an immediate solution, but I'm going to monitor this thread in hopes of an easy fix posted by someone else.  This problem has been mentioned many times before and the easy fix is to have Ed change the code to comply with the spec.  I just posted a request in the VWS bug report form in hopes that it makes it into a future release:


Bwahahahahaha..... you're a real comedian there. ;)  ... do you really think that he'll take notice of your reminder request, even though he's pretty much ignored fixing it up since it was first brought up years ago by many people in there.
Brendan,
vk4blp
IRLP 6857 Echolink 672767


Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9297
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Can you modify HTML attributes on the fly?
« Reply #5 on: November 21, 2006, 12:02:36 PM »
The short answer to your question about modifying HTML attributes on the fly is "Yes".  It can be done with either JavaScript or PHP .. can you give me a pointer to the page you'd like to have the title= attributes added to the alt= attributes, and I'll give it a try :-)

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline Anole

  • Forecaster
  • *****
  • Posts: 585
    • http://pineislandweather.com
Re: Can you modify HTML attributes on the fly?
« Reply #6 on: November 21, 2006, 12:20:17 PM »
I wrote a PERL script that does exactly this and also removes any duplicate entries from the mesomap "<map>. It removes the <base> tag which is in an "illegal" position and does some other cleanup as well. It also formats the title attribute data to shorten it  as much as possible(changing "North" to "N" for example) because there is a limitation on how much data some browsers will display on the mouseover before they truncate.

I'm not using it at the moment because I can't get it to run from a PHP include after a hosting change and I kind of placed figuring that out on the backburner.

To make this work you need to create a template in VWS that contains the following:

Code: [Select]

<table>
  <tr>
    <td><img src="wximg/mesomap.jpg" alt="SWFL Conditions" ></td>
  </tr>
</table>


The code is below, it might help give you a starting point:

Code: [Select]

#!/usr/bin/perl
# DON"T FORGET TO SET THE PATH!
# mesomapfix 1.0

# exercise some good cgi practices
$|= 1;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use Fcntl;
use strict;
use vars qw($count $line $key $temp
            @vwsfile @fixed
            %linelist
);

# plug the DoS security holes in CGI.pm
$CGI::DISABLE_UPLOADS = '1';
$CGI::POST_MAX = 1024 * 10; # max post size is 10K

#untaint the $ENV{path}
$ENV{'PATH'} = '/usr/lib';

#############################
# variables for your system #
#############################

# mesomap file
# MUST BE FULL PATH!
my $mesomap_file = '/your/path/to/mesomap/file';

##############
# here we go #
##############

# start by opening the VWS produced file
sysopen(VWSFILE, "$mesomap_file", O_RDONLY)
or die "Couldn't open mesomap file \"$mesomap_file\" for read";
@vwsfile=<VWSFILE>;
close VWSFILE;
chomp @vwsfile;

#get rid of the garbage
$vwsfile[2] =~ s/\<td\>//i;
$vwsfile[2] =~ s/\<\/td\>//i;
$vwsfile[2] =~ s/Conditions\"\>/Conditions\" \/\>/i;
$vwsfile[3] =~ s/\<base target=\"_blank\"\>//i;
$vwsfile[3] =~ s/\<map /\<map id=\"MESOMAP\" /i;
push (@fixed, $vwsfile[2], "$vwsfile[3]\n");

# filter out all the entries that are off the map
@vwsfile = grep !/coords.*\-/, @vwsfile;

# grab each area line put ID's and make a hash
%linelist = ();
$count = "0";
foreach $line (@vwsfile){
        if ($line =~ /\<area.*ID\: /){
           if (!$linelist{$line}) {
              $linelist{$line} = $count;
           } # end if
        } # end if
        $count++;
} # end foreach

# start processing
foreach $key (keys %linelist) {
        push (@fixed, "$vwsfile[$linelist{$key}]\n");
        $count= '1';
        until ($count == '10') {
              push (@fixed, "$vwsfile[$linelist{$key}+$count]\n");
              $count++;
        } # end until
        my $last_alt = $vwsfile[$linelist{$key}+$count];
        chop($last_alt);
        chop($last_alt);
        push (@fixed, "$last_alt\n");
        $count= '1';
        $temp = "title=\"";
        until ($count == '10') {
              my $temp1 = $vwsfile[$linelist{$key}+$count];
              chop $temp1;
              if ($count == 2) {
                    $temp1 =~ s/Time://;
                    $temp1 = substr($temp1, 7);
                    $temp1 = substr($temp1, 0, 5);
              } # end if
              if ($count == 6) {
                    $temp1 =~ s/in//;
              } # end if
              if ($count == 9) {
                 $temp1 =~ s/North/N/;
                 $temp1 =~ s/South/S/;
                 $temp1 =~ s/East/E/;
                 $temp1 =~ s/West/W/;
              } # end if
              $temp .= "$temp1\,";
              $count++;
        } # end until
        my $temp1 = $vwsfile[$linelist{$key}+$count];
        chop $temp1;
        chop $temp1;
        $temp1 =~ s/Hourly Rain:/Rain:/;
        $temp .= "$temp1";
        $temp =~ s/\s//;
        $temp =~ s/City://;
        $temp =~ s/\sTemp://;
        $temp =~ s/DewPoint:/DPt:/;
        $temp =~ s/Humidity:/RH:/;
        $temp =~ s/Barometer:/Bar:/;
        $temp =~ s/Wind Speed:/Wind:/;
        $temp =~ s/Wind Gust:/Gust:/;
        $temp =~ s/Wind Dir:/Dir:/;
        $temp =~ s/°F//g;
        $temp =~ s/:\s/:/g;
        $temp =~ s/mph//g;
        push (@fixed, "$temp \/>\n");
} # end foreach
push (@fixed, '</map>');
# print it

print "Content-type: text/html \n\n";
print "@fixed";
print "\n";

######################
# common subroutines #
######################

###################################################################################
# print_error: subroutine to output error messages. Useful for debugging as well. #
###################################################################################
sub print_error {
my $error = shift;
print "content-type: text/html \n\n";
print "$error";
exit(0);
} # end sub print_error

Offline Anole

  • Forecaster
  • *****
  • Posts: 585
    • http://pineislandweather.com
Re: Can you modify HTML attributes on the fly?
« Reply #7 on: November 21, 2006, 12:57:11 PM »
Had a few moments so I finally fixed this on my page. You can see the results here:

http://weather.anolecomputer.com/area.php

The file that's uploaded and manipulated is here:

http://weather.anolecomputer.com/mesomap.txt

You'll probably have to view source to se the difference in the output.

I made a slight modification to the PERL script and instead of reposting the code I just modified it in my post above.

To include it on a PHP page, use:

<?php virtual ("/scgi-bin/mf3.cgi"); ?>

substituting the right virtual path and file name. Note the virtual path is the equivalent to a relative URL.

EDIT: forgot to mention the output is xhtml strict compliant.

Offline mikejeep

  • Member
  • *
  • Posts: 29
Re: Can you modify HTML attributes on the fly?
« Reply #8 on: November 21, 2006, 01:07:32 PM »
Well, I had sent an e-mail to Ed about this last night before I posted my message, thinking that might be a better wide-scale solution.  This morning we exchanged a few messages to clarify the problem... and he fixed it!  The TITLE attribute will now be generated by VWS, instead of ALT.

IE users will see no change, but it should now work for all Netscape browsers and Firefox users will get "partial" tooltips.  Firefox currently has a bug where long tooltips and line breaks are not interpreted correctly, but it appears to be one of the issues near the top of the priority list due to complaints by web developers.

So, I imagine whenever p21 is released, this will be included.  Until then, thanks for the script, Anole! :)

-Mike

Offline Anole

  • Forecaster
  • *****
  • Posts: 585
    • http://pineislandweather.com
Re: Can you modify HTML attributes on the fly?
« Reply #9 on: November 21, 2006, 01:15:09 PM »
Nice! I brought this up to Ed at least twice and never got any movement. I also asked him to take out the <base> tag because it wasn't compliant but never heard a single response back.

One thing the script does is remove the problematic line feeds and shorten the length of the title attribute to help with the truncating. The number of characters displayed in mozilla for the title is suprisingly small which makes it almost impossible to display all the data if the site name is more than four characters.

Offline mikejeep

  • Member
  • *
  • Posts: 29
Re: Can you modify HTML attributes on the fly?
« Reply #10 on: November 21, 2006, 01:28:49 PM »
It's funny, I see all the stories about Ambient's support, but I have been lucky (knock on wood!) that I get replies from Ed almost instantly when I e-mail him, even if it's just to say "I don't plan on doing that".  Now, if I can just convince him to put Davis' storm rain variable in a HTML tag, I would be a happy camper...

Regarding the Firefox tooltips, there is an extension that fixes the bug with long or wrapping tooltips; you can download it here: https://addons.mozilla.org/firefox/1715/

Requiring a download of another program to view your site properly is not usually a good solution for your users, but it's a small file and I am going to reference it on my page until the bug is fixed.

-Mike

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9297
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Can you modify HTML attributes on the fly?
« Reply #11 on: November 21, 2006, 01:46:45 PM »
Nice coding job, Anole!  :!:

Looks like there's no need for me to explore this.. you've got it licked!

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline Anole

  • Forecaster
  • *****
  • Posts: 585
    • http://pineislandweather.com
Re: Can you modify HTML attributes on the fly?
« Reply #12 on: November 21, 2006, 01:47:23 PM »
Quote from: "mikejeep"
Regarding the Firefox tooltips, there is an extension that fixes the bug with long or wrapping tooltips; you can download it here: https://addons.mozilla.org/firefox/1715/

Requiring a download of another program to view your site properly is not usually a good solution for your users, but it's a small file and I am going to reference it on my page until the bug is fixed.

-Mike


My thoughts exactly. I have a huge aversion to telling visitors that they have to install some software, no matter how innocuous, to properly view my web site.

Offline Anole

  • Forecaster
  • *****
  • Posts: 585
    • http://pineislandweather.com
Re: Can you modify HTML attributes on the fly?
« Reply #13 on: November 21, 2006, 01:49:42 PM »
Quote from: "kenmtrue"
Nice coding job, Anole!  :!:

Looks like there's no need for me to explore this.. you've got it licked!

Best regards,
Ken


Actually, I've been wanting to port it to PHP.  :wink:  :wink:  nudge nudge.

Offline weatheroz

  • Senior Contributor
  • ****
  • Posts: 216
    • http://www.jimboombaweather.com
Re: Can you modify HTML attributes on the fly?
« Reply #14 on: November 21, 2006, 07:22:06 PM »
Quote from: "mikejeep"
Well, I had sent an e-mail to Ed about this last night before I posted my message, thinking that might be a better wide-scale solution.  This morning we exchanged a few messages to clarify the problem... and he fixed it!  The TITLE attribute will now be generated by VWS, instead of ALT.


I am absolutely staggered that after the many many requests, he's finally bitten the bullet and actually responded to the dozens and dozens of requests for it.

I don't know who you are or what you did, but to save the bacon of all the vws users please do it again. :)


Well done Mike ! :)
Brendan,
vk4blp
IRLP 6857 Echolink 672767


Offline W3DRM

  • Forecaster
  • *****
  • Posts: 3360
    • Emmett Weather
Re: Can you modify HTML attributes on the fly?
« Reply #15 on: November 21, 2006, 08:33:22 PM »
Mike, I think you've had the same luck with Ed as I have. I've worked with him on a problem with VWS over the past few months (VWS just flat-out crashing for no reason at all). After many attempts he has gotten the specific problem fixed. Ed has been very responsive to my requests for help. Many of his responses were literally in minutes after I emailed him.
Don - W3DRM - Emmett, Idaho --- Blitzortung ID: 808 --- FlightRadar24 ID: F-KBOI7
Davis Wireless VP2, WD 10.37s150,
StartWatch, VirtualVP, VPLive, Win10 Pro
--- Logitech HD Pro C920 webcam (off-line)
--- RIPE Atlas Probe - 32849

Offline up10ad N9RJH

  • USA Weather Finder
  • WxElement panel
  • Forecaster
  • *****
  • Posts: 578
  • Station will be back up someday...
    • Forecaster without a site
Re: Can you modify HTML attributes on the fly?
« Reply #16 on: November 21, 2006, 09:21:32 PM »
I tried to word my reply earlier to not take any direct aim at Ed or VWs for their previous lack of response on this issue.  However, I have to go on record that I agree with Oz that we have gone for years without fixes or even acknowledgments to several major issues and some minor ones (like this one).  I'm just very happy to see this newfound responsivness in the VWs camp.
Rick (N9RJH)
Have you joined USAWeatherFinder.com yet?

Offline Anole

  • Forecaster
  • *****
  • Posts: 585
    • http://pineislandweather.com
Re: Can you modify HTML attributes on the fly?
« Reply #17 on: November 22, 2006, 09:29:38 AM »
I just made another small change to the PERL script that removes any entries that are "off the map". Depending on how you have your mesonet settings configured in VWS, it's possible that you may end up with entires in your mesomap that are outside of the boundaries of your image. The script now detects these and prevents them from being included in the html markup. This is something I've been meaning to do since I wrote this way back when.

You can see the difference if you view the source and compare these two outputs:

with off map entries left in: http://weather.anolecomputer.com/scgi-bin/mf3.cgi

with off map entries removed: http://weather.anolecomputer.com/scgi-bin/mf4.cgi

As before, instead of reposting all of the code I just updated my previous post.

Offline Anole

  • Forecaster
  • *****
  • Posts: 585
    • http://pineislandweather.com
Re: Can you modify HTML attributes on the fly?
« Reply #18 on: November 22, 2006, 01:04:39 PM »
Driving out to a customer site this morning I realized I'm going to have to rewrite that new regex a bit. I'm looking for a "-" in the alt text and if it's there the entry is ignored. That's a bit FLcentric  :). I'll need to do something a little more specific to tell it to only ignore if the "-" is in the coords area.

Offline Anole

  • Forecaster
  • *****
  • Posts: 585
    • http://pineislandweather.com
Re: Can you modify HTML attributes on the fly?
« Reply #19 on: November 22, 2006, 02:31:19 PM »
Here's a modification to the PERL script to take into account that folks outside of SWFL might see temps in the negative digits!

Change

Code: [Select]
@vwsfile = grep !/\-/, @vwsfile;

to

Code: [Select]
@vwsfile = grep !/coords.*\-/, @vwsfile;

 

anything