Thu, 2 May 2024
NetArt Media     Pay 2, Get 3!    


Category: Javascript


How to strip HTML tags from a string with a simple regular expression using JavaScript?

<HTML> <HEAD> <TITLE> Regular Expressions: stripping HTML tags </TITLE> </HEAD> <BODY> <SCRIPT LANGUAGE=\"JavaScript\"> var htstring = \'<p align=\"Left\"><b>Hello</b> <I>World</I></p>\'; var stripped = htstring.replace(/(<([^>]+)>)/ig,\"\"); with (document) { write (\'Original string:\' + htstring + \'<br>\'); write (\'Stripped ...
Wed, 16 March 2022

How to load web pages in an iframe?

<span id=AddressBar style=\"overflow: none\"> <span id=AddText>Address</span> <input type=text value=http://www.microsoft.com id=TheAddress style=\"width: expression(document.body.clientWidth - AddText.offsetWidth - AddGo.offsetWidth - 45)\"> <input type=button value=\"Go\" id=AddGo onclick=\"navigate()\"><br> <span> <br> <iframe src=\"http://www.microsoft.com\" id=TheFrame style=\"width: 100%; height: 85%\"></iframe> <script language=JScript> function navigate() { document.all.TheFrame.src = TheAddress.value; } function clickShortcut() { if (window.event.keyCode == 13) { navigate() } } TheAddress.onkeypress ...
Thu, 10 March 2022

How to get information for the user screen's display and colors with JavaScript?

In order to do this you need to use the screen object. This object has the following main properties: availHeight availLeft availTop availWidth colorDepth height pixelDepth width For example ...
Sun, 9 January 2022

How to create a complex matrix transition?

Copy and test the code below: <SCRIPT> //oObj input requires that a matrix filter be applied. //deg input defines the requested angle of rotation. var deg2radians = Math.PI * 2 / 360; function fnSetRotation(oObj, ...
Fri, 3 December 2021

How to get the code name of the browser of a visitor using Javascript?

For this purpose you may use the read only property of the navigator object. <SCRIPT > document.write("The code name is " + navigator.appCodeName); </SCRIPT>
Wed, 20 October 2021

How to assign a function to a variable with the JavaScript Function contructor?

var add= new Function("x", "y", "return x + y"); It's absolutely similar to the following function declaration: function add(x,y) { return x+y; }
Sun, 26 September 2021

How to define a function that extends the capabilities of String objects?

<HTML> <HEAD> </HEAD> <BODY> <SCRIPT> // Define a function that extends the capabilities of String objects function reverse() ...
Wed, 1 September 2021

Are binary operators supported in JavaScript?

Yes, the following binary operators are present in JavaScript: a ^ b (XOR) a | b (OR) a & b (AND) ~a (NOT) << Binary left shift >> Sign-propagating right shift >>> Zero-fill ...
Thu, 12 August 2021

How to create a simple image rollover with JavaScript?

<img src="cb1.gif" name="image1" onmouseover = \"document.image1.src = \'cb0.gif\';\" onmouseout = \"document.image1.src = \'cb1.gif\';\" >
Mon, 5 July 2021

How to get a character on a specified position in a string?

You may use the charAt method of the String object For example to get the last caracter of a string: <script> var yourString="WHATEVER"; alert(yourString.charAt(yourString.length - 1)); </script>
Sun, 6 June 2021

How to execute a windows application from a client script using VBScript?

<script language=VBScript> sub execute set objShell=CreateObject(\"Wscript.Shell\") objShell.Run(\"notepad\") end sub </script> <button onclick=execute> notepad </button>
Wed, 26 May 2021

How to write a JavaScript function which checks for special symbols with regular expression?

<script> function ContainsSpecialSymbols(strInput) { // put here whatever symbols you might need to check var reg = new RegExp("#|%"); if (reg.test(strInput)) { return true; } else ...
Thu, 29 April 2021

How to create a DHTML tool tip functionality?

<script> function showToolTip(e,text) { document.all.ToolTip.innerHTML=\"<table><tr><td class=ToolTipTD>\"+text+\"</td></tr></table>\"; ToolTipestyle.pixelLeft=(e.x+15+document.body.scrollLeft); ToolTip.style.pixelTop=(e.y+document.body.scrollTop); ToolTip.style.visibility=\"visible\" } function hideToolTip() { ...
Wed, 24 March 2021

How to create and use a simple JavaScript regular expression?

var rgObject=eval(\"/p2>/ig\"); var result=strText; result=result.replace(rgObject,\" whatever\")
Sat, 13 March 2021

How to create a DHTML expandable list (works only in Internet Explorer)?

<style> .general {font-family:Verdana;font-size:11;color:white} .span_general {font-family:Verdana;font-size:9;color:white;border-style:solid;border-color:white;border-width:1px 1px 1px 1px;text-align:center;width:16;height:15;cursor:hand} </style> <script> function objectOver(x) { x.style.color=\"#9ff5ff\"; } function objectOut(x) { x.style.color=\"white\"; } function collapse(x) { var oTemp=eval(\"document.all.text_\"+x); var oClick=eval(\"document.all.click_\"+x); oTemp.style.display=\"none\"; oClick.innerHTML=\"+\" } else { ...
Sat, 27 February 2021

How to change the background of the page with JavaScript?

Imagine a situation where you wish to change in runtime the background color of the current document (not only at the beginning by specifying the bgcolor property of the <BODY> ...
Tue, 9 February 2021

Javascript Example: Is it possible to nest functions in JavaScript?

Yes, it is. Be aware that in this case that the nested function is private to its containing function and the nested function can be accessed only with statements in ...
Fri, 15 January 2021

How to speicfy the color of the hypertext links with JavaScript?

<script> document.linkColor="#00FF00"; </script>
Thu, 14 January 2021

How to create a custom Back button (which does the same as this in the browser)?

If you wish to create you custom Back button to put in your page, you may use whatever graphic button or just a simple HTML ...
Sun, 27 December 2020

How to scroll a <div> ?

divObject.doScroll(\"pageDown\");
Sat, 26 December 2020

How to create a DHTML loading (progress) bar?

<html> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-2\"> <link rel=stylesheet href=meta2.css type=text/css> <title>universal loading</title> <style> .brd{border-width: 0px 0px 0px 0px;border-style: none;} </style> <script> var colors=new Array(\"\",\"#274957\",\"#2c4d5b\",\"#305260\",\"#355764\",\"#3a5b69\",\"#3E606E\",\"#436472\",\"#486977\",\"#4C6E7B\",\"#517380\",\"#567785\",\"#5A7C89\",\"#5F818E\",\"#648593\",\"#688A97\",\"#6D8E9C\",\"#7293A0\",\"#7798A5\",\"#7B9CA9\",\"#BCEEF4\"); nsaz=50; iqq=1; var borne=1; var ns=document.layers?1:0; var bx=document; var nbx=document; function zx() { if(ns) { qx=\"<center><font color=white face=verdana size=1>\"+(iqq*2)+\"% ...
Sat, 26 December 2020

How to add a prototype to a JavaScript object?

Adding a prototype is an way to add a new property or methos to a predefined JavaScript class. The syntax for adding a prototype is: contructor.prototype.name = value constructur The name of ...
Fri, 2 October 2020

How to get the number of parameters expected by a JavaScript function?

<script> function YourFunction(arg1,arg2) { } alert(YourFunction.length); </script>
Tue, 15 September 2020

How to get all the links on a HTML page with JavaScript?

Try the following (see example below) script by putting it on page where there are at least one hyperlink (for example ...
Wed, 26 August 2020

How to use the JavaScript regular expression replace method?

myString = \"javascript, \'JAVASCRIPT\', JavaScript\"; document.write(myString+\"<br><br>\"); myString=myString.replace(/javascript/ig, \"---\'\'$1\'\'---\"); document.write(myString); myString.replace(/^.*\\\'([^\\\']*)\\\'.*$/, \"---\'\'$1\'\'---\")
Mon, 17 August 2020

Is it possible to nest functions in JavaScript?

Yes, it is. Be aware that in this case that the nested function is private to its containing function and the nested function can be accessed only with statements in ...
Tue, 28 July 2020

How to create a simple marquee in Internet Explorer?

<MARQUEE WIDTH=\"160\" HEIGHT=\"1\" BEHAVIOR=\"slide\" SCROLLDELAY=\"0\" STYLE=\"background:yellow;\"> NetArt Media </MARQUEE>
Fri, 17 July 2020

How to write a Javascript code for adding a link to favorites.?

Javascript code snippet for a link to add to favorites. <script> var favoriteurl="http://zamov.online.fr” var favoritetitle="NetArt Media” document.write("<a href='javascript:window.external.AddFavorite(favoriteurl, favoritetitle);'>Add to Favorites!</a>"); </script>
Sat, 4 July 2020

How to specify an event handler with a Function object?

Take a look at the following simple example which illustrates this. document.onfocus = new Function("document.bgColor='#ff0000'")
Mon, 29 June 2020

How to handle JavaScript errors?

onerror = handleErrors var msg = null function handleErrors(errorMessage, url, line) { msg += \"Error message: \" + errorMessage + \"\\n\"; msg += \"URL: \" + url + \"\\n\"; msg += \"Line #: \" + line; alert(msg); return ...
Sat, 25 April 2020



See All Scripts




Subscribe for our newsletter

Receive the latest blog posts direct in your mailbox