[Tutorial -> Trick] Link checking using JavaScript (ny myself)

This is a discussion on "[Tutorial -> Trick] Link checking using JavaScript (ny myself)" within the JavaScript Forum section. This forum, and the thread "[Tutorial -> Trick] Link checking using JavaScript (ny myself) are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Nov 8th, 2007, 07:09
Reputable Member
Join Date: Nov 2007
Location: India
Posts: 150
Blog Entries: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up [Tutorial -> Trick] Link checking using JavaScript (ny myself)

This a tutorial as well as a trick to check if files exists! You can call it a link checking tool
Even this is writtem by myself http://javascript.biologyformhtcet.c...avascript.html
Quote:
Check if file exists or not using JavaScript

This is particularly helpful if you are setting up your website and want to make sure that all the necessary files exist. This checking can be done most conveniently on 'localhost' machine. Checking files on a remote server is also possible if appropriate changes are made to the script. I personally prefer that you use Opera browser to increase productivity.

Step 1: Create custom error page 404(file not found). Tutorials for the same can be found here and here.
Inside custom error page for Error 404, insert the below code:
Code: Select all
 
<script>
window.close()
</script>
Step 2: copy the below code AS IT IS into a blank text file and save that file with as check_file_exists_or_not.html extension:
Code: Select all
<html>
<head>
<script>
function check()
{
fileName=prompt("Enter only file name here,Eg: index.html or contact_form.php,\n127.0.0.1/filename","")
{
window.open("<A href="http://127.0.0.1/"+fileName">http://127.0.0.1/"+fileName+"")
}
}
</script>
</head>
<body>
<input type="button" value="Check URL" onclick="check()">
</body>
</html>
Step 3: Put this newly created into www folder.
Step 4: Start the server
Step 5: Request the page by typing the following in address bar: 127.0.0.1/check_file_exists_or_not.html . The page would load as show below:

Note: If you have saved the file with other name and/or to other directory, you will need to type in the URL accordingly.
Step 6: Click on 'Check URL'

Enter the file name at the prompt box. Be sure to enter the proper extension as well (Eg: .html or .php or .cgi). If you want to check a file that lies in sub directory, then enter relative path to that accordingly
Eg: images/buttons/roundbutton.gif is the relative path to image file named 'roundbutton.gif' which is located in buttons folder. buttons folder is located inside images folder, and images is located inside the main directory
Once you enter the filename, click OK.A new tab would open if the page existed(i.e. link is working). If the new tab opens but closes immediately and you automatically return to the 'Check URL' page, it means link is not working properly.

Rationale behind this trick:
Page exists ---> Page loads ---> Page exists (to close that page quickly and return to 'Check URL' page hit Ctrl+W)
Page does NOT exist ---> Custom error page loads ---> Custom error page closes its window due to window.close() snippet ---> and you return to the Check URL page


( In Internet Explorer, every time the custom error page tries to close it self, it would ask for confirmation whether to allow the page or not to close itself and this would take a toll on time )

Note: I am working on enhancing this script to check existence multiple files simultaneously. Perhaps, you could just enter all files names at once and then hit the go button! Keep your fingers crossed!
Last Blog Entry: Cross browser nuisance (Feb 11th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Nov 8th, 2007, 08:48
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: [Tutorial cum Trick] Link checking using JavaScript (ny myself)

How is this useful? I don't see how it's better than simply typing the file path in the address bar.

Why not use an efficient link checking tool instead, such as Link Checker for Firefox? It quickly tests all links on a page, and then colour-codes them according to their status (basically, broken links are red and good links are green).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Nov 8th, 2007, 08:58
Reputable Member
Join Date: Nov 2007
Location: India
Posts: 150
Blog Entries: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: [Tutorial cum Trick] Link checking using JavaScript (ny myself)

Quote:
Originally Posted by MikeHopley View Post
How is this useful? I don't see how it's better than simply typing the file path in the address bar.

Why not use an efficient link checking tool instead, such as Link Checker for Firefox? It quickly tests all links on a page, and then colour-codes them according to their status (basically, broken links are red and good links are green).
^Ya, I realize that, but I am having something else in ma mind, not simply file existance cheking!
Last Blog Entry: Cross browser nuisance (Feb 11th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Nov 8th, 2007, 09:17
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: [Tutorial cum Trick] Link checking using JavaScript (ny myself)

Quote:
Originally Posted by RohanShenoy View Post
^Ya, I realize that, but I am having something else in ma mind, not simply file existance cheking!
Oooooh, how enigmatic.

Perhaps you should share what you have in mind. That way, people might find a reason for using your method.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Nov 8th, 2007, 12:13
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: [Tutorial -> Trick] Link checking using JavaScript (ny myself)

Quote:
Originally Posted by MikeHopley View Post
Why not use an efficient link checking tool instead, such as Link Checker for Firefox?
ah! Thanks for that link Mike

There's also the Link checker provided by the W3C.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Nov 8th, 2007, 12:19
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: [Tutorial -> Trick] Link checking using JavaScript (ny myself)

Quote:
Originally Posted by karinne View Post
ah! Thanks for that link Mike

There's also the Link checker provided by the W3C.
One word of warning: last time I tried, the Firefox Link Checker conflicts with another extension, Word Count. You can't have them both running (correctly) at the same time.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Nov 8th, 2007, 12:21
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: [Tutorial -> Trick] Link checking using JavaScript (ny myself)

Thanks for the warning ... fortunately, I don't have Word Count extension
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Nov 8th, 2007, 12:52
Reputable Member
Join Date: Nov 2007
Location: India
Posts: 150
Blog Entries: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: [Tutorial -> Trick] Link checking using JavaScript (ny myself)

I had this in my mind.
Many times, webmasters have a lot of files and sometimes, they may forget to create one file ot may have not named it properly or some other error. What I want this to do is tell the names of non-existent files. Even i am seeing no method now to use a list, but still thinking.
Last Blog Entry: Cross browser nuisance (Feb 11th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Javascript tutorial hegerp JavaScript Forum 2 Nov 29th, 2007 13:31
javascript checking for broken links Code_breaker JavaScript Forum 6 Nov 8th, 2007 07:19
Link popularity checking? preston9u1 Scripts and Online Services 9 Oct 31st, 2007 13:26
Javascript - Anti browser checking satimis JavaScript Forum 7 Aug 8th, 2007 15:43


All times are GMT. The time now is 21:50.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42