Cast for two

Showing posts with label html. Show all posts
Showing posts with label html. Show all posts

Sunday, August 02, 2009

Set all links target to _blank on a XHTML 1.0 Strict using jquery

As explained here, opening links in a new window is no longer possible via target=_blank in XHTML 1.0 strict. This code is a workaround using Javascript:


function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") &&
anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}
window.onload = externalLinks;

A link with attribute rel set to external will open in a new window:

<a rel="external" href="http://castfortwo.blogpspot.com/">cast42</a>

On the Friendfeed realtime embed code, I saw they use jquery to do the job:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.js">
<script type="text/javascript">
$("body").mousedown(function(e) {
for (var target = e.target; target; target = target.parentNode) {
if (target.tagName == "A") {
if ((document.location.href.split("#")[0] + "#") == target.href) {
return;
}
target.target = "_blank";
return;
}
}
});
</script>

The advantage is that all links will open in a new window, except if the refere to an anchor in the page. Hence there's no need to add the attribute rel to each anchor.

Friday, December 14, 2007

New Analytics script not accepted by Blogger

Google asks to update the Google Analytics script to:

<script type=”text/javascript”>
var gaJsHost = (("https:" == document.location.protocol) ? " https://ssl." : "http://www.");
document.write("\<script src='" + gaJsHost + " google-analytics.com/ga.js' type='text/javascript'>\<\/script>" );

var pageTracker = _gat._getTracker(“UA-xxxxxx-x”);
pageTracker._initData();
pageTracker._trackVisit();
</script>

When entering this in to the Blogger HTML template, I get an error:


Open quote is expected for attribute "{1}" associated with an element type "type".

If you don't need the secure http access, you can simplify the script to:

<script src='http://www.google-analytics.com/ga.js' type='text/javascript'>
</script>
<script type='text/javascript'>
var pageTracker = _gat._getTracker("UA-xxxxxxx-x"); pageTracker._initData(); pageTracker._trackPageview(); </script>

Please only use the above code if you urgently want to test the new script. It might be wise to wait until the Google engineers have ironed out this issue if you do not want to put your huge analytics income at risk ;-)

Sunday, November 18, 2007

Web pages especially for Iphone/Ipod Touch

I was wondering how the embed a media file into HTML for the mobile Safari browser on Apple's Iphone or Ipod Touch. Therefore, I looked up how others are doing it and what's in the documentation Apple:

  1. BBC has made a portal to its podcasts : http://www.bbc.co.uk/radio/podcasts/directory/ip/ or you can just go to bbc.co.uk/podcasts.

    The code used to embed the mp3 podcasts is:

    <embed width="100%" height="22" enablejavascript="true" controller="false" autostart="false" pluginspage="www.apple.com/quicktime/download" src="http://downloads.bbc.co.uk/podcasts/northernireland/nimusic/nimusic__20071112-2215.mp3"/>

    More info on BBC podcast portal.

  2. Also Apple makes their trailers available in an Ipod Touch / Iphone friendly way. The URL is http://www.apple.com/trailers/iphone/
    Here's the HTML code that Apple uses to embed the Beowulf movie:

    <embed src="http://movies.apple.com/trailers/iphone/images/greenband_320x133.png" href="http://movies.apple.com/movies/paramount/beowulf/beowulf-fte_i320.m4v"
    target="myself" width="320" height="133"
    controller="false"
    autoplay="false"
    scale="1" cache="true" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/">

    Ars Technica has some screenshots of Apple trailers on the Iphone.
  3. The code proposed by Apple looks like this:

    <script src="AC_QuickTime.js" language="JavaScript" type="text/javascript"></script>
    QT_WriteOBJECT_XHTML('http://d2.mikseri.net/m/30a/30007249206/Frozen%20Silence%20-%20Cherish.mp3', '32', '16', '',
    'autoplay', 'false',
    'emb#bgcolor', 'black',
    'cache','false',
    'align', 'top');

    The URL is to a piece of music of the album "Frozen Silence" by Matti Paalanen.

  4. Also the indie site http://ourstage.com has Iphone specific pages according to Techcrunch. But when surfing to that page on my Ipod Touch i get no specific content.


To get those HTML codes, go to about:config in Firefox and set the value of general.useragent.extra.firefox from something like 'Firefox/2.0.0.9' to 'Useragent "Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML,like Gecko) Version/3.0 Mobile/3A100a Safari/419.3' and then surf to the URL for ipod touch or iphone and inspect the page source.

Sunday, September 16, 2007

Testing video upload in Blogger

Recently, Google's Blogger added the ability to upload video. While the video is uploaded you can continue working on your blogpost. Neat.
Here is the result:


This is a screenshot of how the post appears in Google Reader:

Also in Netvibes, the video appears (but twice ;-)).

This is the code generated (with long encoded URL's edited out):


<object width="320" height="266" class="BLOG_video_class"

id="BLOG_video-c97b748c29cea499"

classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"

codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">

<param name="movie" value="http://www.blogger.com/img/videoplayer.swf?videoUrl=LONGVIDEOURL&nogvlm=1&thumbnailUrl=LONGTHUMBURL">

<param name="bgcolor" value="#FFFFFF">

<embed width="320" height="266"

src="http://www.blogger.com/img/videoplayer.swf?videoUrl=LONGVIDEOURL

&nogvlm=1&thumbnailUrl=LONGTHUMBURL&

messagesUrl=video.google.com%2FFlashUiStrings.xlb%3Fframe%3Dflashstrings%26hl%3Den"

type="application/x-shockwave-flash">

</embed>

</object>
<a href="rtsp://rtsp-youtube.l.google.com/video.3gp?fmt=13&cid=c97b748c29cea499" type="video/3gpp">

<img width="320" height="266" alt="video"

src="http://video.google.com/ThumbnailServer2?app=blogger&contentid=c97b748c29cea499

&offsetms=5000&itag=w320&sigh=f52nsu-i5tuyLzJ7tEY1Q8a5Y2M"

class="BLOG_mobile_video_class" id="BLOG_mobile_video-c97b748c29cea499">

</a>

So if the Flash object can not be rendered, at least a link to a RTSP server with a 3GPP video is presented. The latter is probably the case on mobile browsers (Iphone?). The movie size is 320x266. Probably this corresponts to a default 4:3 aspect ratio and 320x240 pixels video surface. So there are 26 lines at the bottom for the controls. So if the the original footage has 16:9 format, black borders are added automatically so that aspect ratio is maintained.

Conclusion: Google Blogger upload works well, uploading goes fast and allows continuing editing while uploading goes on. Nicely done!

Friday, August 31, 2007

Embedding MP4 in HTML with Flash 9 beta Moviestar

From Jeroen Wijering I found a way to play MP4 movies in a webpage using the new Flash Version 9 beta, nicknamed Moviestar. It uses SWFObject to embed a Flash file using Javascript and the mediaplayer by Jeroen.
This is the code:


<script type="text/javascript" src="swfobject.js"></script>


<p id="player1">

<a href="http://www.macromedia.com/go/getflashplayer">

Get the Flash Player</a> to see this player.

</p>


<script type="text/javascript">

var s1 = new SWFObject("mediaplayer.swf","single","384","224","7");

s1.addParam("allowfullscreen","true");

s1.addVariable("file","test.mp4");

s1.addVariable("image","preview.jpg");

s1.addVariable("overstretch","none");

s1.addVariable("smoothing","false");

s1.write("player1");

</script>

In the same directory above code is residing, store swfobject.js,test.mp4,preview.jpg and mediaplayer.swf.
The result looks like this:

I don't understand yet when clicking on fullscreen, the video does not resize but that's probably an option of mediaplayer I have to enable. Also, I have the impression the movie is first downloaded before playback starts. I am quite sure the header atoms in test.mp4 are in front of the file. So the movie should faststart. Here is an example where it does work. Any suggestions welcome in the comment.

UPDATE:
leaving out the overstrech variable so that is get the default true value, stretches the movie to fullscreen in fullscreen mode. No problem now with the fast start. So the code becomes:

<script type="text/javascript" src="swfobject.js"></script>


<p id="player1">

<a href="http://www.macromedia.com/go/getflashplayer">

Get the Flash Player</a> to see this player.

</p>


<script type="text/javascript">

var s1 = new SWFObject("mediaplayer.swf","single","384","224","7");

s1.addParam("allowfullscreen","true");

s1.addVariable("file","test.mp4");

s1.addVariable("image","preview.jpg");

s1.write("player1");

</script>

Sunday, July 29, 2007

How to include a HTML page into blogger posts ? (final)

I already undertook three attemps (attempt 1, attempt 2 and attempt 3) to include a Google Sheet into a blogger post without much succes. I almost surrendered but I got a new idea. I started from the proposal I found in "Insert HTML page into another HTML page" that basically proposed the following code:

<!--[if IE]>
   <object classid="clsid:25336920-03F9-11CF-8FD0-00AA00686F13" data="some.html">
      <p>backup content</p>
   </object>
<![endif]-->
<!--[if !IE]> <-->
   <object type="text/html" data="some.html">
      <p>backup content</p>
   </object>
<!--> <![endif]-->

The above code is very good for direct inclusion into a HTML page, but Blogger filters out the conditionals for selecting the code based upon the user agent. So it's not the solution we're seeking for. But then I got another idea. Maybe I could insert the above code using Javascript that IS allowed to be inserted in Bloggers HTML. In that way, it's possible to circumvent the restriction in Blogger HTML. I pasted the code into a HTMl-to-Javascript convertor. This gave me:

<script language="JavaScript" type="text/javascript">
<!--
function writeJS(){
var url = 'http://spreadsheets.google.com/pub?key=pzcvT0aLrnhuxklkh_C8AVA&output=html&gid=0&single=true&widget=true';

var str='';
str+='<!--[if IE]>';
str+='<object classid="clsid:25336920-03F9-11CF-8FD0-00AA00686F13" data="'+url+'">';
str+='<p>backup content<\/p>';
str+='<\/object>';
str+='<![endif]-->';
str+=' <!--[if !IE]> <-->';
str+='<object type="text\/html" data="'+url+'">';
str+='<p>backup content<\/p>';
str+='<\/object>';
str+='<!--> <![endif]-->';
document.write(str);
}
writeJS();
//-->
</script>


that renders as:

Above code reders nicely in Firefox and Safari but not in Interet Explorer 6.
Therefore I changed the code such that in IE an iframe is displayed and otherwise an object. The code was put into javascript:

<script language="javaScript" type="text/javascript"    src="http://lode.nachtergaele.googlepages.com/includeHTML3.js">
</script>


and on IE6 it renders to:


So finally, we start to view some light:


  1. First, include into blogger a Javascript:

    <script language="JavaScript" src="http://lode.nachtergaele.googlepages.com/includeHTML3.js" type="text/javascript" ></script>

  2. Put in the Javascript file the following Javascript code:

    <!--
    function writeJS(){
    var str='';
    str+='<!--[if IE]>';
    str+=' <iframe src="http://spreadsheets.google.com/pub?key=pzcvT0aLrnhuxklkh_C8AVA&output=html&gid=0&single=true&widget=true" width='550' height='370' frameborder='0'>';
    str+='<p>backup content</p>';
    str+='</iframe>';
    str+='<![endif]-->';
    str+='<!--[if !IE]> <-->';
    str+=' <object type="text/html" data="http://spreadsheets.google.com/pub?key=pzcvT0aLrnhuxklkh_C8AVA&output=html&gid=0&single=true&widget=true" width='550' height='370' frameborder='0'>';
    str+=' <p>backup content</p>';
    str+=' </object>';
    str+='<!--> <![endif]-->';
    document.write(str);
    }
    writeJS();
    //-->
  3. Alternatively, Javascript can detect the user agent as well. This leads to the following code:

    <!--
    function writeJS(){
    var str='';
    if (navigator.appName.indexOf("Microsoft") != -1) {
       str+=" <iframe       src='http://spreadsheets.google.com/pub?key=pzcvT0aLrnhuxklkh_C8AVA&output=html&gid=0&single=true&widget=true'       width='550' height='370' frameborder='0'>";
       str+='<p>backup content</p>';
       str+='</iframe>';
    } else {
       str+=" <object type='text/html'       data='http://spreadsheets.google.com/pub?key=pzcvT0aLrnhuxklkh_C8AVA&output=html&gid=0&single=true&widget=true'       width='550' height='370' frameborder='0'>";
       str+=' <p>backup content</p>';
       str+=' </object>';
    }
    document.write(str);
    }
    writeJS();
    //-->

  4. And that wil do the trick. The Javascript code generates HTML code that includes an Iframe if viewed by Internet Explorer and an object for other browsers. I agree that this is maybe a big detour just to able to include an object. And hopefully it shows up in the feed readers....


In 50 ways to include HTML into a Blogger post an overview is given of all kinds of techniques and can be used for testing.

How to (not?) include a HTML page into blogger posts ? (continued 2)

Much to my despair, I noticed the Google Spreadsheet included in a blog post of this blog does not render nicely (even after some digging into the issue, see post1 and post2) in Microsoft Internet Explorer 6 and 7:
While reading Make Magazine in Google Reader, I noticed that the Youtube movie of post "Thomas Edsison hates cats" was coming trough nicely. I looked up the HTML code in the RSS feed and adapted the code I found for displaying inline HTML code. It boils down to something like this:

<![CDATA[<p>
<object data="URL to HTML page" type="text/html" width="520" height="350">
<embed src="URL to HTML page" type="text/html" width="520" height="350"></embed>
</object></p>
<p>Title of HTML Page <a href="URL to HTML page">Link</a></p>]]>

Unfortunatly, Blogger does not accept the <![CDATA[. It reports "tag is broken". I removed the CDATA:

<p>
<object data="URL to HTML page" type="text/html" width="520" height="350">
<embed src="URL to HTML page" type="text/html" width="520" height="350"></embed>
</object></p>
<p>Title of HTML Page <a href="URL to HTML page">Link</a></p>


which renders to (with URL of the Google Spreadsheet):





Blog of colleagues Juli 2007 Link


which renders on Microsoft Internet Exporer 6 as:

Bummer. The object does not display nicely. Ok, lets see what Google Reader makes from it:

Archhh. This is even worse. It must have been the CDATA. Why is Blogger not accepting that I put CDATA into a blogpost. Give me full control of the HTML in the feed please !
Or maybe, as a last resort conflicting with my open standards first DNA, I could try this (as a kind of revance ;-)): export the Google Sheet to Microsoft Excel and include the Excel sheet with MIME type : application/vnd.ms-excel
The code would be like this:

<p>
<object data="URL to HTML page" type="application/vnd.ms-excel" width="520" height="350">
<embed src="URL to HTML page" type="application/vnd.ms-excel" width="520" height="350"></embed>
</object></p>
<p>Title of HTML Page <a href="URL to HTML page">Link</a></p>

which causes Firefox 2.0.5 on OSX to pop up this dialogue:

Ok, I surrender. Maybe the Iframe code Google Sheets proposes it not that bad at all. If any body has a better idea, please let me know.

Friday, July 27, 2007

How to include a HTML page into blogger posts ? (continued)

In How to include a HTML page into blogger posts ? I explored using the more general object tag to include an external page of HTML into a blogger post. You would for example want to do this when discussing a published Google Document Sheet. When checking the appearence of the post in the RSS reader Google Reader, I noticed that the alternate text showed up:

This brought me to an idea for an improvement. I took a screenshot of the Google Sheet as displayed in my browser and loaded up the picture to the blog post. Next I moved the blurb of code for the picture:

<a onblur="try {parent.deselectBloggerImageGracefully();}catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEis6fFWgw_EHUdXJ9ez9cL69nHhZWKtx-fGWF_glB7NmFob_7n_2G5KcUPFtB8iBBv1v30grM3GWevFiTlQo7jTnNgS1YUm2upPmP14c6fq3WHpLm8BSwIRsFl5fEZhR_BBqSGXpw/s1600-h/Screenshot_5.png">
<img style="display:block; margin:0px auto 10px;
text-align:center;cursor:pointer; cursor:hand;"
src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEis6fFWgw_EHUdXJ9ez9cL69nHhZWKtx-fGWF_glB7NmFob_7n_2G5KcUPFtB8iBBv1v30grM3GWevFiTlQo7jTnNgS1YUm2upPmP14c6fq3WHpLm8BSwIRsFl5fEZhR_BBqSGXpw/s400/Screenshot_5.png"
border="0" alt=""id="BLOGGER_PHOTO_ID_5091774679559246658" /></a>

into to object tag enclosure:

<object data="URL to HTML page" type="text/html" width="520" height="350">

<a onblur="try {parent.deselectBloggerImageGracefully();}
catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEis6fFWgw_EHUdXJ9ez9cL69nHhZWKtx-fGWF_glB7NmFob_7n_2G5KcUPFtB8iBBv1v30grM3GWevFiTlQo7jTnNgS1YUm2upPmP14c6fq3WHpLm8BSwIRsFl5fEZhR_BBqSGXpw/s1600-h/Screenshot_5.png">
<img style="display:block; margin:0px auto 10px;
text-align:center;cursor:pointer; cursor:hand;"
src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEis6fFWgw_EHUdXJ9ez9cL69nHhZWKtx-fGWF_glB7NmFob_7n_2G5KcUPFtB8iBBv1v30grM3GWevFiTlQo7jTnNgS1YUm2upPmP14c6fq3WHpLm8BSwIRsFl5fEZhR_BBqSGXpw/s400/Screenshot_5.png"
border="0" alt=""id="BLOGGER_PHOTO_ID_5091774679559246658" /></a>

</object>

The result is that in Google Reader a picure of the Google sheet shows up:

If you want that the browser is directed to the published HTML page of the Google Sheet when clicking on the picture of the sheet, you can change the URL of the href of the pciture:

<object data="URL to HTML page" type="text/html" width="520" height="350">

<a onblur="try {parent.deselectBloggerImageGracefully();}
catch(e) {}" href="URL to HTML page">
<img style="display:block; margin:0px auto 10px;
text-align:center;cursor:pointer; cursor:hand;"
src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEis6fFWgw_EHUdXJ9ez9cL69nHhZWKtx-fGWF_glB7NmFob_7n_2G5KcUPFtB8iBBv1v30grM3GWevFiTlQo7jTnNgS1YUm2upPmP14c6fq3WHpLm8BSwIRsFl5fEZhR_BBqSGXpw/s400/Screenshot_5.png"
border="0" alt=""id="BLOGGER_PHOTO_ID_5091774679559246658" /></a>

</object>


Of cource, you can also copy and past the HTML code directly into the blog post. Then you get this:
URLEst. ValuePage RankWebsite GraderTechnorati AuthorityTechnorati Rank

http://peterdecroubele.be205945237167,118

http://www.koenfillet.be$1910477--

http://www.werner.be94944928226,753

http://koenfillet.blogspot.com/44547756103,461

http://www.braincubes.be/23421241,367,488

http://castfortwo.blogspot.com/823668779,588

http://www.patdonnez.be/log/index.php80313--

http://detender.wordpress.com/5046310638,771

http://joro.wordpress.com/4224122,505,981

http://217.19.231.156/apps/blog_david/40259--

http://mertenswouter.com/blog/11050--

http://stielo.blogspot.com/206213,900,217

http://hetruimesop.blogspot.com/0043-7,931,033

http://jeroenvanaert.blogspot.com/0043-7,931,033

http://myjumps.blogspot.com/0042-7,931,033


which is not that bad. Only something with the first row went wrong.
A bit fiddling with the HTML code allows to obtain this:

URLEst. ValuePage RankWebsite GraderTechnorati AuthorityTechnorati Rank
http://peterdecroubele.be205945237167,118
http://www.koenfillet.be$1910477--
http://www.werner.be94944928226,753
http://koenfillet.blogspot.com/44547756103,461
http://www.braincubes.be/23421241,367,488
http://castfortwo.blogspot.com/823668779,588
http://www.patdonnez.be/log/index.php80313--
http://detender.wordpress.com/5046310638,771
http://joro.wordpress.com/4224122,505,981
http://217.19.231.156/apps/blog_david/40259--
http://mertenswouter.com/blog/11050 - -
http://stielo.blogspot.com/206213,900,217
http://hetruimesop.blogspot.com/0043-7,931,033
http://jeroenvanaert.blogspot.com/0043-7,931,033
http://myjumps.blogspot.com/0042-7,931,033


Every table row contained a bogus
<td class="rAll"> </td>
that I just deleted.

Thursday, July 26, 2007

How to include a HTML page into blogger posts ?

In the previous post, I included HTML code generated from a published Google Sheet. To do so, I first used the code proposed when publishing a Google Document and selecting Blogger as target.

This is basically the HTML code Google proposes to post into the HTML code of post on Blogger:


<iframe src="URL to HTML page" frameborder="0" height="350" width="520">
</iframe>

This works when viewing the blog post in a browser, but when reading the post with a feed reader, the HTML iframe is sometimes ommitted. Recently, I read an interesting article "The object tag - embed content in valid strict HTML -" arguing for the use of the HTML object tag as follows:

<object data="URL to HTML page" type="text/html" width="520" height="350">
alt : <a href="URL to HTML page">alternate text</a>
</object>

The advantage of using the object tag is that the HTML object (the Googele sheet) appears when reading the blog post inline with netvibes:

In Google Reader, the alternate text appears (in this case the URL to the HTML of the document):

In iGoogle, it is even worse. There even the alternate text does not appear:

The above picture displays the Atom feed from Google (http://castfortwo.blogspot.com/feeds/posts/default) and the feed from feedburner (http://feeds.feedburner.com/cast42).

Conclusion is that even using the object tag is no ideal solution to include an exteral HTML page into a blog post. But if you opt to do it, the use of the object tag may be preferred instead of using an Iframe. In case you would know a better solution, do not hesitate to add a comment.