Archive for the ‘All’ Category.

‘Hello JavaScript’

Prequisites:

A basic understanding of html.

Resources:

A list of various resources on JavaScript can be found here (XXX).

‘Hello JavaScript’ in a popup dialog

JavaScript is best known for making webpages more dynamic. The webbrowser loads the plain JavaScript code along with the html code and then executes it. Every webbrowser today allows to switch off execution of loaded JavaScript.

JavaScript code can be inserted in a lot of places within the html code. But the cleanest way is to define a <script> section within the html head.

JavaScript code can be embeded into the html text or it can be outsourced into another text file which then must be referenced in the html code.

That is all to know to code the first “Hello world!” example using JavaScript.

Create a html file with the following content:

<html>
 <head>
 <script type="text/javascript">
 alert("Hello JavaScript, in a popup dialog!");
 </script>
 </head>
 <body>
 </body>
</html>

Whenloaded it in a web browser a popup dialog with the text “Hello JavaScript, in a popup dialog!” will be displayed.

The outsourced version of this example looks like the following. In the html file the script section is replaced by a script reference.

<html>
 <head>
 <script src="hello_js_dialog.js" type="text/javascript"></script>
 </head>
 <body>
 </body>
</html>

And the JavaScript code is placed in the sepparated file named “hello_js_dialog.js”.

alert(“Hello JavaScript, in a popup dialog!”);

When loaded in a webbrowser it behaves exactly like the first example.

‘Hello JavaScript’ in modified html

JavaScript can be used to modify html code that is already loaded and processed by the webbrowser. When the html code is modified, the browser will re-render the page, thus displaying the changes.

The following example changes the text of a html tag:

<html>
 <head>
 </head>
 <body>
 <h1>Hello html!</h1>
 <p>Nice to meet you.</p>
 </body>
 <script type="text/javascript">
 document.getElementsByTagName("h1")[0].firstChild.data="Hello JavaScript, in modified html!";
 </script>
</html>
Note:

In this example the <script> section is inserted  after the part of the html code it references to (the <h1> tag). This is because the webbrowser processes the html code line by line and tag by tag. Also JavaScript code is executed when the webbrowser runs over it. It does not first complete processing all the html code. If the script would be placed in the html head, like in the previous examples, the script would not be able to find the appropriate tag, as this tag was not yet processed by the webbrowser and the browser ‘has no knowledge of it’.

JavaScript Resources

Tutorials and documentation

A good read to start with JavaScript is selfhtml. Pittily it is only available in german language. (http://de.selfhtml.org/javascript/index.htm)

Editors and IDEs

Linux

On Ubuntu i use GEdit, which has a syntax highlighter for allmost every coding language.

Windows

PSPad

Rap News 6

Embedding YouTube videos into WordPress

That’s an easy one. On your WordPress edit post page switch to html-view and insert the html-code to embed provided by youtube at the desired position in your article.

The section you insert may look something like this

<object classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″ width=”425″ height=”344″ codebase=”http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0″><param name=”allowFullScreen” value=”true” /><param name=”allowscriptaccess” value=”always” /><param name=”src” value=”http://www.youtube.com/v/71kckb8hhOQ&amp;hl=de_DE&amp;fs=1&amp;” /><param name=”allowfullscreen” value=”true” /><embed type=”application/x-shockwave-flash” width=”425″ height=”344″ src=”http://www.youtube.com/v/71kckb8hhOQ&amp;hl=de_DE&amp;fs=1&amp;” allowscriptaccess=”always” allowfullscreen=”true”></embed></object>

Switching back to text view you can add some additional line breaks before and after the video.

That’s all.

Experimenting with hotlinking

Hotlinking refers to embedding resources from a host (that is not yours) into your webpages, forumposts, etc. . Unless the hoster of the resource gives explicit permission, hotlinking should be omited as it has some negativ implications for the hoster of the resource.

How to hotlink

What if i find a resources,  i want to embed in my blog without hosting it on my server? Well, should be easy, shouldn’t it?

E.g. this cartoon on http://www.nichtlustig.de/toondb/100202.html. But i don’t want the whole page, just the picture.

The first thing i do, is to find out if it is available via a static link. First i try by looking at the resource address via a right mouse click->properties (which should be available in every browser). And – ha, there i see this address http://www.nichtlustig.de//comics/full/100202.jpg which shows exactly the picture when i enter the url in a browser. Embedding it in this blog is made easy by wordpress. I’m not going into details on that.

And that is what it looks like:

nichtlustig.de, cartoon, duck in bakery

nichtlustig.de, cartoon, duck in bakery

That’s it. Please not that at the time i wrote this article hotlinking to resources at nichtlustig.de was possible. If nichtlustig.de decides to prevent hotlinking, this image can not be vewed anymore or there may be a replacement that clrifies that hotlinking is not wanted. And please don’t sue me. I have done this for reasons of showing how it is done. I have provided links and props to nichtlustig.de.

The important facts are, now every time this page on my blog is loaded, the browser will download the picture from the host at nichtlustg.de. To a visitor of this page it makes no difference if the picture is hosted on my server or on another. I can dsiplay content that is not mine but a can make it appeare like it is mine (imagine the cartoon not beeing labeled with ‘www.nichtlustig.de’ in the lower left corner).

Additional comments for hotlinkers:

It is not always that easy. Sometimes site owners try to protect static content via javascripts, that do show some warning when you right click on the content. Not that bad too. In that case you just turn off javascript or have a look at the plain html. Maybe use the famouse firefox add-on ‘firebug‘ to examine a sites html, resources and links. Not that the address of the resource has to be static, not the page url. In the above case the resource address is ‘http://www.nichtlustig.de//comics/full/100202.jpg’. The url of the page it is from is ‘http://www.nichtlustig.de/toondb/100202.html’.

If a site does not provide content via static links, then you are done. No static link, no static linking.

Additional comments for resource hosters:

If you run a site, hotlinking may make you furious for two reasons:

  1. Your content is displayed in a distinct location, where you do not have control over the context in which it is displayed. The usage may run counter to your original idea of how to use it.
  2. Every page request in the distinct location generates traffic at your host, because the content resides on it and is downloaded from it. The distinct location just embeds it via a static link.

There is a solution to this problem. Webservers can be configured to not to serve to hotlinks. Just search the internet for your webservers name and the term ‘hotlink‘.

Apache webserver

IIS