Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Get Blogger Post - Rss Feed in our website using javascript

Task: Get Blogger post - Rss Feed in our website using javascript.

Description: It shows 2 post and summery of post without any html tag like without any image. If you want to show all content then just use content as it is without any operation on it.


­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<div id="blog-feed"></div>
<script type="text/javascript">
  google.load("feeds", "1");

  var feedContainer=document.getElementById("blog-feed");
  var feedURL="https://hemantrautela.blogspot.com/feeds/posts/default?alt=rss";
  var postsReturned=2;
  var rssoutput="<div style='background-color:green'>";
  var stringWithHTML="";

  function rssFeedSetup(){
    var pullFeed=new google.feeds.Feed(feedURL)
    pullFeed.setNumEntries(postsReturned)
    pullFeed.load(showFeed)
  }

  function showFeed(result){
    if (!result.error){
      var thefeeds=result.feed.entries;
      for (var i=0; i<thefeeds.length; i++)
      {
       stringWithHTML = thefeeds[i].content.replace(/<\/?[a-z][a-z0-9]*[^>]*>/ig, ""); // remove html tag
      if(stringWithHTML.length>200) // just a summery of post
       {
       stringWithHTML= stringWithHTML.substring(0,200);
       var n = stringWithHTML.lastIndexOf(" ");
       stringWithHTML= stringWithHTML.substring(0,n)+"...";
       }
      rssoutput+="<div><a target='_blank' style='color:#ddd; font-size:16px;' href='" + thefeeds[i].link + "'rel='nofollow'>" + thefeeds[i].title + "</a><br/>" + stringWithHTML +"</div><hr/>"
      }
      rssoutput+="</div>";
      feedContainer.innerHTML=rssoutput;
    }
    else
      {
       rssoutput ="There was an error loading the blog posts.";
       feedContainer.innerHTML=rssoutput;
      }
    }
    window.onload=function(){
    rssFeedSetup()
  }

</script>­­­

Manage CSS & Message Box(javascript) using C#.NET , ASP.NET Code at run time...

Task:  How can open a pop-up message box using asp.net or add css/javascript using c# code. (JavaScript alert box).

Description:  After the completing some task we have to show a message for user so that we need a message box. Here the first code is for creating a CSS dynamically using code and second one for generating a message box using c# asp.net code.

C# Code : For Dynamic Css C# Code

  protected void Page_Load(object sender, EventArgs e)
    {
  string c = "#f0ff0f";
        string d = "#0f0f00";
        LiteralControl ltr = new LiteralControl();
        ltr.Text = "<style type=\"text/css\" rel=\"stylesheet\">" +
                    @".d
                    {
                        color:" + c + @";
                    }
                    .d:hover
                    {
                        color:" + d + @";
                    }
                    </style>
                    ";
        this.Page.Header.Controls.Add(ltr);
    }

.

////////////////// Message Box in asp.net/c#.net website

C# Code : For Message Box in Asp.Net C#

    public void msgbox(string message)
    {
        string msg = @"alert('" + message + "');";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "s1", msg, true);
    }




On Button Click How Open A page in new window in asp.net - c# code


Task: Open a new window using c# code in asp.net website/web application. 
Description: The problem is this we can use Response.Redirect() method for redirect/open  new webpage in same window, But how we can open a new page in new window.

So that I use javascript code(alert box) for popup new window in c# code behind file as describe below. I write below code on Button Click Event.

// Dynamic Alert box javascript using c# code in asp.net

 protected void btngeneraterecipt_Click(object sender, EventArgs e)
    {
        try
        {
            string queryString = "billformat.aspx";
            string jquery = "window.open('" + queryString + "');";
            ScriptManager.RegisterStartupScript(this,this.GetType(), "pop", jquery, true);
        }
        catch (Exception ee)
        {
            Label1.Text = ee.Message;
        }
    }