ShareThis

Showing posts with label HTML. Show all posts
Showing posts with label HTML. Show all posts

Friday, December 28, 2012

Speed up your HTML/CSS with Zen Coding

Here is a video of a new tool available for writing less HTML and getting MORE out of it! The system works by allowing you to enter abbreviations of tags with attributes, even child nodes, and expand them into actual HTML. Looks pretty nifty, definitely going to give this a try.



 You can read more about it and get the download in the Smashing Magazine article.

Sunday, October 7, 2012

[jQuery] Collapse div content in jQuery UI tabs

I have a page that I wanted to collapse the tab content, but keep the tab header there so that it could be expanded on later.

If you are using jQuery Tabs, you will notice that calling $('#tabs').slideToggle(); hides the entire tabs display. To hide only the content and keep the tabs, try this:


Full Source:



<div id="tabs">
 <ul>
  <li><a href="#tab1">Tab A</a></li>
  <li><a href="#tab2">Tab B</a></li>
  <li><a onclick="$('#tabs div').slideToggle()">Collapse Content</a></li>
 </ul>
<div id="tab1">Stuff A</div>
<div id="tab2"> stuff B</div>


</div>

Note: You will need the following jQuery pieces to get Tabs working:
  • UI Core
  • UI Widget
  • jQuery 1.7.2

Thursday, September 20, 2012

[HTML] Add hover-over text to buttons or inputs

You can easily add titles to buttons or any input items using the "title" attribute in html.

See for yourself:


Thursday, August 9, 2012

jQuery Alternative to using iFrames

You can accomplish the same effect of an iFrame using jQuery's .Load functionality (ajax).

Here is a very simple process to switch over:

Instead of having an iFrame for your content, create a <div>


<div id="content">
Stuff...
</div>

Next, on your navigation pane, simply create onclick functions that call a javascript function that does the following:

<script type="text/javascript">
function articleLinkClick()
{
  $('#content').load('article.html');
}
</script>
This will make an ajax call and load article.html inside your content div. You can do the same with .php documents, and the serverside code will run as normal.

Thursday, July 19, 2012

ascx control causing shift when viewing page (loading late)

This is a pretty simple fix. The problem is that the control loads late (possibly waiting for the server response to populate its data). The fix is to wrap the controls in a <div> element. Then set the style attribute:

<div id="controlWrapper" style="display:hidden;">
controls
</div>

You can use javascript or jquery to set the display style once the controls have loaded, so they display at the same time and no shifting occurs.

Tuesday, July 10, 2012

[HTML] Where does JavaScript go on an HTML/PHP page?

The best place for Javascript code to go in a HTML or PHP document is at the end. See a discussion on WHY on StackOverflow. Basically, it boils down to the fact that when a browser renders JS, it is in a single-thread, causing the rest of the page to pause in rendering until the JS render is complete. By adding the JS at the end of the page, the content will load first and then the JS will render.

Sunday, June 24, 2012

[HTML] Creating an iframe from a div

Iframes are a nuisance. They have problems with nested scripts and they have a large overhead which kills scalability. 



<div style="border:solid 1px #000000; width:500px; height:50px; overflow:auto;">
<p>Paragraph 1</p>
<p>paragraph 2</p>
</div>

Wednesday, June 13, 2012

Easiest Blogger insert code snippets methods

These sites let you paste code in and get html-escaped colored code back that is easy to read.

#1 - http://hilite.me/

#2 - http://formatmysourcecode.blogspot.co.uk/




span align right is not working right

Problem: span align right does not align right

Fix: try using style="float:right;" on your html element that should align right.

Example Code:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
var fade = false;


$(document).ready(function(){
  $("div").click(function(){
    if(!fade)
{
    $("div").fadeTo("slow",0.25);
     fade = true;
}
else
{
   $("div").fadeTo("slow",1);
fade = false;
}
  });
});
$(document).ready(function(){
  $("#close").click(function(){
    $("div").fadeOut(1000);
});
});
</script>
</head>
<body>
<div style="background:yellow;width:300px;height:300px">
<button>Click to Fade</button>
<span align="right">
<button style="float:right;" id="close">X</button></span>
</div>
</body>
</html>
Test it out on http://jsbin.com/#source -- Make sure you include jquery to see the fade stuff !

Monday, June 4, 2012

Browsers that support dd HTML tag

Internet Explorer Firefox Opera Google Chrome Safari

Friday, April 13, 2012

HTML Input form restrict to numbers only

Here is an awesome script from htmlcodetutorial.com on how to restrict an input textbox to numbers only. View the source here.



<SCRIPT TYPE="text/javascript">
<!--
// copyright 1999 Idocs, Inc. http://www.idocs.com
// Distribute this script freely but keep this notice in place
function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

//-->
</SCRIPT>
Now we can create a numbers only field using the onKeyPress attribute. For our first example, we'll create a field which accepts five digits as for a United States ZIP Code. Set the onKeyPress attribute exactly like it is here:
<FORM ACTION="../cgi-bin/mycgi.pl" METHOD=POST>
U.S. ZIP Code: 
  <INPUT NAME="dollar" SIZE=5 MAXLENGTH=5
   onKeyPress="return numbersonly(this, event)">
  <INPUT TYPE=SUBMIT VALUE="go">
</FORM>


Sunday, March 4, 2012

[FIX] PHP Header( ... ) opens page in Frame instead of new page

Issue: 
Trying to redirect using "header ( ... )"  in PHP. Instead youre getting it opened up in your iFrame

Example:


Fix: 
Add the following to your <a href="..." > links </a >
target="_top"
That'll do it!

[FIX] Failed to load resource: the server responded with a status of 403 (Forbidden)

Scenario: 

You're trying to grab some images in your html / php code that calls a css style sheet. Then youre running into this error in your browser console:
Failed to load resource: the server responded with a status of 403 (Forbidden)
I found that the problem was using the incorrect slashes for the image directory.

The Wrong Way:
"images\main\ico.png"
The Right Way
"images/main/ico.png"
Hope this helps. Didn't find any solutions online for the problem, but used some common sense to figure it out.

Monday, November 7, 2011

[JAVA] Thread Crawler & Bulk Image Downloader


My latest project; a thread crawler and bulk image downloader through Java. This project was easier than expected with only a few roadbumps on the way that were solved pretty quickly.

Here is how the process works:

When you first start the application, it asks to paste  all urls (currently only accepts one at a time, but future versions will allow bulk copy paste.

So, lets crawl a thread. For example, I will use this thread:

From here, the program will analyze the links on this page. It will save all same-domain links and crawl those for images (this is handy when most picture sites have thumbnails that lead to full-size images). Those "children" URLs are crawled after the main url is crawled, and any image over a given size (Im using 15KB) is then saved via byte Stream to the project folder. The byte Stream is not the fastest utility, but it works ok and gives you time to hunt other picture sites while it works.

From here, the process iterates over the  given list of user-submitted URLs and those URLs' children URLs; scouring them all for pictures.

Download log:

And now to see the final product...


Final notes:

Ive noticed some imperfections with the code as far as websites go. Some websites have had more problems parsing than others, and popular items such as Google Images don't work at all. Future implementations will contain special cases for those popular websites.

Business Aspect:

While this was a relatively easy project; there is room for marketing it as an independent application (although, in such an early beta, it would not go live for quite some time.) It would require some reworking and polishing, as well as developing an attractive, and easy-to-use graphical user interface.

I hacked together a simple GUI for it:

However, this is done in NetBeans while my project is in Eclipse. I dont necessarily have the patience to port either to the other, so while Im just using this for personal use, I'll stick to Eclipse's System.in.











Sunday, October 30, 2011

[JAVA] Grab all hyperlinks from a website - Source Code


import java.io.*;
import java.net.*;
import javax.swing.text.*;
import javax.swing.text.html.*;

class GetLinks {
public static void main(String[] args) {
EditorKit kit = new HTMLEditorKit();
Document doc = kit.createDefaultDocument();

// The Document class does not yet
// handle charset's properly.
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
try {

// Create a reader on the HTML content.
Reader rd = getReader(args[0]);

// Parse the HTML.
kit.read(rd, doc, 0);

// Iterate through the elements
// of the HTML document.
ElementIterator it = new ElementIterator(doc);
javax.swing.text.Element elem;
while ((elem = it.next()) != null) {
MutableAttributeSet s = (MutableAttributeSet) elem
.getAttributes().getAttribute(HTML.Tag.A);
//System.out.println(s);
if (s != null) {
System.out.println(s.getAttribute(HTML.Attribute.HREF));
}
}
} catch (Exception e) {
e.printStackTrace();
}
System.exit(1);
}

// Returns a reader on the HTML data. If 'uri' begins
// with "http:", it's treated as a URL; otherwise,
// it's assumed to be a local filename.
static Reader getReader(String uri) throws IOException {
if (uri.startsWith("http:")) {

// Retrieve from Internet.
URLConnection conn = new URL(uri).openConnection();
return new InputStreamReader(conn.getInputStream());
} else {

// Retrieve from file.
return new FileReader(uri);
}
}
}