Add Read More note with web site link When Someone Copies Text from your website.

Hello,

Below code use full when you want to add your link when some one copy from your website.


Put below java script code in main Master page.




function addLink() {
    //Get the selected text and append the extra info
    var selection = window.getSelection();
    pagelink = ". Read more at: " + document.location.href;
    copytext = selection + pagelink;
 //Create a new div to hold the prepared text
    newdiv = document.createElement('div');

    //hide the newly created container
    newdiv.style.position = 'absolute';
    newdiv.style.left = '-99999px';

    //insert the container, fill it with the extended text, and define the new selection
    document.body.appendChild(newdiv);
    newdiv.innerHTML = copytext;
    selection.selectAllChildren(newdiv);

    window.setTimeout(function () {
        document.body.removeChild(newdiv);
    }, 100);
}
document.addEventListener('copy', addLink);



Hope this will help.

Posted in | 0 comments

Format JSON Date.

Hello,

Below is way to format JSON Date.

var date = new Date(parseInt(jsonDate.substr(6)));

The substr function takes out the "/Date(" part, and the parseInt function gets the integer and ignores the ")/" at the end. The resulting number is passed into the Date constructor.

if you are using newtonsoft then see at below location.
https://www.newtonsoft.com/json

Posted in | 0 comments

How to bind Event on dynamically created elements in JQuery.


We can achieve this using jQuery.fn.on.  
(Details document available at https://api.jquery.com/on/#on-events-selector-data-handler)

Let’s have an example.

Suppose your page creating element with the class name 'Applyevent'
you would bind the event to a parent which already exists
mainly 'document'




$(document).on('mouseover', '.Applyevent', function(){

    // what you want to happen when mouseover 

    // occurs on elements that match '.Applyevent'

});



Any parent that exists at the time the event is bound is fine. For example






$('.dynamicgenerate').on('click', 'button', function(){

    // code here

});







<div class="dynamicgenerate">

     

              <---- Dynamic Controls here ---->

              --- Suppose <button>


</div>

Posted in Labels: | 0 comments

How to remove specific session in asp.net




You can set session element to null.

Example:-

Session["sessionname"] = null;

Posted in | 0 comments

How to parse html in C#?

First

You Can use Html Agility Pack
Details is availbale at 
http://html-agility-pack.net/?z=codeplex

This is an agile HTML parser that builds a read/write DOM and supports plain XPATH or XSLT (you actually don't HAVE to understand XPATH nor XSLT to use it, don't worry...). It is a .NET code library that allows you to parse "out of the web" HTML files. The parser is very tolerant with "real world" malformed HTML. The object model is very similar to what proposes System.Xml, but for HTML documents (or streams).

Second

using Fizzler that takes a jQuery/Sizzler approach to selecting HTML elements. It's based on HTML Agility Pack.Details available at below location.

https://code.google.com/archive/p/fizzler/

Posted in | 0 comments