CoderBlog.NET
Tengiz Tutisani's blog.

 
Useful Links:
 
LanguageBox 
 
Language

 
SearchBox 
 
 
ArchiveBox 
 
Archive
<February 2012>
SuMoTuWeThFrSa
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910
 
CategoriesBox 
 
Categories
  ASP.NET (5)
  Ajax (1)
  C# (7)
  Common (1)
  HTML (3)
  JavaScript (5)
  Products (1)
  SEO (1)
  SQL (1)
  Visual Studio (1)
  Windows (1)
 
FriendSitesBox 
 
Friend Sites
  AdMoney Project
  Cайт о гитаре и музыке!
  Design Studio IMAGINE
 
CustomContentBox [1] 
 



 
 
How to dynamically include JavaScript script reference into html
JavaScript’s day
Posted By:   tengo
At:   5/14/2009 5:25:00 PM
 

One of my friends asked me how to dynamically include a reference to the JavaScript file into an html file.
Sincerely to say, I didn't know what to answer. But no additional effort was needed to find the answer, it's easy.
If you are familiar with JavaScript, then you can think of it yourself and you'll find the answer.

I wrote a function in JavaScript which makes all the work: dynamically creates object corresponding to the "<script>" tag, assigns it's "src" property a value of file name, and then adds this object to the current document. Have a look:

<script language="javascript" type="text/javascript">
function IncludeJS(file)
{
var scr = window.document.createElement("script");
scr.src = file;
document.body.appendChild(scr);
}
</script>


All works fine. One more thing I would mention here:
When invoking a method that is contained in dynamically referenced script file, always make a little more coding to ensure that no script errors will be thrown. For this purpose, my test button's "onclick" event checks, if the method that SHOULD be in the included file, exists. Look at this button tag:

<input type="button" value="Invoke Sample Method" onclick="if (window.SampleMethod) SampleMethod()" />

That's all about today's JavaScript.


Filed Under:   JavaScript | HTML |
Post Tags:   dynamically | file | function | html | include | javascript | js | script | src |
  Comments [0]



 
 
HTML Editing
How it works
Posted By:   tengo
At:   5/8/2009 9:55:00 AM
 

Did you know that almost any HTML control can be switched into edit mode? This effect can be achieved easily: just add CONTENTEDITABLE attribute to the component that must be an editor.

Place the following tag into the source of you HTML page and view it in browser:

<div CONTENTEDITABLE>some editable text</div>

As you can see, the text "some editable text" is editable now. In the easiest editing scenario, you can copy-paste the content from Word document to that editable area. For more complicated scenarios you can use document.execCommand method. (For advanced scenarios you can use a free and ready to use HTML editor tinyMCE).
Now let's talk about how you can get the content of that div as HTML. Depending on your needs, you can just get the content and do some operation with it. In my practice I had few situations when I wanted the content to be submitted to the server. As you probably know, only HTML input controls have ability to submit their values to the server. For this purpose, here I consider the code fragment that shows how to move the HTML value of the editable div to a Textarea control that actually can submit its value. The Input-button tag is added to move the content from one control to another.

<div id="text" CONTENTEDITABLE>some editable text</div>
<textarea id="content"></textarea>
<input type="button" value="get HTML content" onclick="content.value=text.innerHTML">

That's all, a little but sometimes very useful thing.
And one more: Button element can be created using not only the standard input tag, but also using a button tag like this:

<button value="some value">some text</button>

Note, that the button has a text "some text" instead of "some value" as you might think at a first look.

Thanks for your time.


Filed Under:   JavaScript | HTML |
Post Tags:   button | contenteditable | div | editor | html | javascript | submit | textarea | value |
  Comments [0]



 
 
Table layout vs. DIV layout
Today's topic
Posted By:   tengo
At:   4/15/2009 2:40:00 PM
 

Today I was discussing this topic with one guy, who is interested in web development. As everyone, he also visits a lot of development forums and finds different approaches of the web site design, discussed on the forums. He said to me that he's interested to learn how to build a web page layout using DIV instead of tables, he gave me a link to the forum topic, where I found an idea of a developer, who supposes this kind of layout is more professional.
I don't want to criticize the developer, any person can have his/her own mind, but my mind sounds a little different than the one from the forum.

Before I continue writing around the topic, for those who don't know what we're talking about:
Table layout means that page's html source contains a <table> tag inside of it's <body> tag, such way, layout and positioning of each element depends on the table structure and layout, as all other elements of the page would be it's child elements.
DIV layout means that every element placed on the page is a child of a <div> element, or is itself, a <div> element. That means layout and positioning of all the elements are controlled by <div> elements.

As I think, both of the solutions are useful, interesting and rather professional. If you ask which one do I prefer, a table layout is the one I prefer.
But I want to mention, in the case of professional and correct using of these layouts, the result will be the same, be sure in that.

I didn't like the topic of the forum that I have read, because there was said that the table layout structure is old enough and in our days it's important to use only a DIV layout. As I understood the author has ambitions to use DIV layout because this one is developed later and supposed to be called as a newer technology approach. But I would say, it's not a reason to throw away a table layout.
At first, if table layout approach is old, that means that this approach is more supported by all the browsers as a default than the new one. Have in mind, none of a browser developer companies have announced the end of table layout support, am I right? (We all remember how everyone moved away from using frames, because such recommendations where announced)
At a second, I would say, a good developer must be familiar with both of these approaches, but not only with one of them.

One more thing: the guy asked me to explain the following fact:
He placed two div elements on the html page, on one line, and then he just resized the browser window, and when the size was smaller that the area containing both DIVs, the second div moved down, under the first one.

It happens because nothing has told to the second div to remain the position in first line, it's like you wrote a paragraph of text, which took several line on the page. Of course in the case of resizing the window, words of the paragraph move and change their line positions depending on the size of the browser's window. Imagine the div is a word, so everything is clear. The div moves to the next line when there is not enough space for it on the current line, like a word in the text.

How to avoid this:
Use a table layout. (A little funny, all the topic was about it)
In details: Insert a table with two cells in a row, place one div in each cells, they will remain in the same row, because table cells don't change their line positions depending on the browser's window size.

But I must say, there is another way also, using DIV layout:
Insert a div element having a width more than both of divs together, and place both divs inside the last inserted div element. That's all, but be careful, if someone entering your web site has a low resolution of a screen, he will have to scroll to the right and left to see everything on your page. But in some cases, using a table layout can bring the same problem.

Several other hints:
To make divs position on the same line, add the following attribute to both of them: style="float: left;"
To assign a width to the div, use the same style attribute as follows: <div style="width: 500px"></dv>

That's all for today.


Filed Under:   HTML |
Post Tags:   design | div | html | layout | style | table |
  Comments [0]



 
CustomContentBox [2] 
 
Useful Links:
 
CategoryViewBox 
 
CoderBlog.NET
  Get your own Blog Engine
  SMS Sending Service
  What do you want to see on CoderBlog.NET?
  IMAGINE.GE created a header image for CoderBlog.NET
  CoderBlog.NET offers link exchange
  Quick language selection added
  CoderBlog.NET ‘s what is what
  Welcome to CoderBlog.NET

  Jump to Category...
 
TagsBox 
 
Popular Tags
aspnetblogcsharpdesigndivengineerrorformhtmljavascript
 
AuthorsBox 
 
Authors
  Tengiz Tutisani  (25)
 
SubscriptionsBox 
 
Subscriptions
Your Email:
 
LoginStatusBox 
 
Site Members
Login
 
Copyright © 2009 . CoderBlog.NET