How to disable all links using jQuery

To disable all links using jQuery you cna use the snippet below.

Samples

jQuery Sample

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

How to open a Website in the default Browser in C# and VB.NET

To open a Website in the default Browser in C# and VB.NET you can use the snippet below.

Sample C#

System.Diagnostics.Process.Start("http://codesnippets.fesslersoft.de/");

Sample VB

System.Diagnostics.Process.Start("http://codesnippets.fesslersoft.de/")

Please rate this snippet

How to reload or rerender the page using AngularJS

To reload or rerender the page using AngularJS you can use the snippet below.

Sample AngularJS

$route.reload();

Please rate this snippet

How to send Data using a WebRequest in C# and VB.NET

To send/post Data using a WebRequest in C# and VB.NET you can use the following snippet.

Sample C#

public static string WebrequestWithPost(string url, Encoding dataEncoding, string dataToPost, string contentType = @"application/x-www-form-urlencoded")
{
	var postDataAsByteArray = dataEncoding.GetBytes(dataToPost);
	var returnValue = String.Empty;
	try
	{
		var webRequest = WebRequest.CreateHttp(url);  //change to: var webRequest = (HttpWebRequest)WebRequest.Create(url); if you are your .NET Version is lower than 4.5
		if (webRequest != null)
		{
			webRequest.AllowAutoRedirect = false;
			webRequest.Method = "POST";
			webRequest.ContentType = contentType;
			webRequest.ContentLength = postDataAsByteArray.Length;
			using (var requestDataStream = webRequest.GetRequestStream())
			{
				requestDataStream.Write(postDataAsByteArray, 0, postDataAsByteArray.Length);
				requestDataStream.Close();
				using (var response = webRequest.GetResponse())
				{
					using (var responseDataStream = response.GetResponseStream())
					{
						if (responseDataStream != null)
						{
							using (var responseDataStreamReader = new StreamReader(responseDataStream))
							{
								returnValue = responseDataStreamReader.ReadToEnd();
								responseDataStreamReader.Close();
							}
							responseDataStream.Close();
						}
					}
					response.Close();
				}
				requestDataStream.Close();
			}
		}
	}
	catch (WebException ex)
	{
		if (ex.Status == WebExceptionStatus.ProtocolError)
		{
			var response = ((HttpWebResponse)ex.Response);
			//handle this your own way.
			Console.WriteLine("Webexception! Statuscode: {0}, Description: {1}",(int)response.StatusCode,response.StatusDescription);
		}
	}
	catch(Exception ex) 
	{
		//handle this your own way, something serious happened here.
		Console.WriteLine(ex.Message);
	}
	return returnValue;
}

Sample VB.NET

Public Shared Function WebrequestWithPost(ByVal url As String, ByVal dataEncoding As Encoding, ByVal dataToPost As String, ByVal contentType As String) As String
    Dim postDataAsByteArray As Byte() = dataEncoding.GetBytes(dataToPost)
    Dim returnValue As String = String.Empty
    Try
        Dim webRequest As HttpWebRequest = WebRequest.CreateHttp(url)  'change to: dim webRequest as var = DirectCast(WebRequest.Create(url), HttpWebRequest) if you are your .NET Version is lower than 4.5
        If (Not (webRequest) Is Nothing) Then
            webRequest.AllowAutoRedirect = false
            webRequest.Method = "POST"
            webRequest.ContentType = contentType
            webRequest.ContentLength = postDataAsByteArray.Length
            Dim requestDataStream As Stream = webRequest.GetRequestStream
            requestDataStream.Write(postDataAsByteArray, 0, postDataAsByteArray.Length)
            requestDataStream.Close
            Dim response As Webresponse = webRequest.GetResponse
            Dim responseDataStream As Stream = response.GetResponseStream
            If (Not (responseDataStream) Is Nothing) Then
                Dim responseDataStreamReader As StreamReader = New StreamReader(responseDataStream)
                returnValue = responseDataStreamReader.ReadToEnd
                responseDataStreamReader.Close
                responseDataStream.Close
            End If
            response.Close
            requestDataStream.Close
        End If
    Catch ex As WebException
        If (ex.Status = WebExceptionStatus.ProtocolError) Then
            Dim response As HttpWebResponse = CType(ex.Response,HttpWebResponse)
            'handle this your own way.
            Console.WriteLine("Webexception! Statuscode: {0}, Description: {1}", CType(response.StatusCode,Integer), response.StatusDescription)
        End If
    Catch ex As Exception
        'handle this your own way, something serious happened here.
        Console.WriteLine(ex.Message)
    End Try
    Return returnValue
End Function

FOR MORE INFORMATIONS SEE THE MSDN: How to: Send Data Using the WebRequest Class

Please rate this snippet

How to ping in Java

To ping in Java you can use the following snippet.

Sample Java

public static void pingUrl(String url, Integer timeOut)
{
	url = url.replace("http://", "");
	try {  
		InetAddress address = InetAddress.getByName(url);  
		System.out.println("Hostname: " + address.getHostName());  
		System.out.println("IP-Address: " + address.getHostAddress());  
		System.out.println("Reachable in " + ((double)timeOut / (double)1000) + " Seconds: " + address.isReachable(timeOut));  
	}  
	catch (UnknownHostException e) {
		System.err.println("Unable to lookup " + url + "; error: " + e);  
	}  
	catch (IOException e) {  
		System.err.println("Unable to reach " + url);  
	}  
}

Please rate this snippet

How to get the text selection in Javascript

To get the text selection in Javascript you can use the following snippet.

Sample Javascript

function GetTextSelection() {
	return (!!document.getSelection) ? document.getSelection() :
	       (!!window.getSelection)   ? window.getSelection() :
	       document.selection.createRange().text;
}

Please rate this snippet

How to download a website source in Java

To download a website source in Java you can use the following snippet.

Sample Java

private static String getUrlSource(String url) throws IOException {
	URL website = new URL(url);
	URLConnection connection = website.openConnection();
	BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
	String input;
	StringBuilder strBuilder = new StringBuilder();
	while ((input = bufferedReader.readLine()) != null){
			strBuilder.append(input);
	}
	bufferedReader.close();
	return strBuilder.toString();
}

Please rate this snippet