Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

jQuery Get Current Page URL & Title | JavaScript Get Current Page URL & Title

Feb 1, 2013
Introduction

Here I will explain how to get current page url in jQuery or get current page url using JavaScript in asp.net

Description:
  
In previous articles I explained
JavaScript Get Current User Location Details, JavaScript Show Google Map with Latitude and Longitude, JavaScript Redirect to Another Page After Some Time Delay and many articles relating to JavaScript, jQuery, asp.net. Now I will explain how to get current page url and title in jQuery or get current page url and title using JavaScript in asp.net

To implement this we need to write the code like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Get Curent Page Url using jQuery in Asp.net</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function () {
var url = $(location).attr('href');
var title= $(this).attr('title');
$('#spn_title').html('<strong>' + title + '</strong>');
$('#spn_url').html('<strong>' + url + '</strong>');
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>Current page URL: <span id="spn_url"></span>.</p>
<p>Current page title: <span id="spn_title"></span>.</p>
</div>
</form>
</body>
</html>
Live Demo

For live demo check below Current Page Url and title values


Current page URL: .
Current page title: .

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

1 comments :

Narendran said...

Hi Sir, Thanks a lot,it helps me a lot.

But I want to do the below stuff,

if(url=="http://domainname.com/")
{
window.location="http://domainname.net/";
}
else if(url=="http://www.domainname.com/")
{
window.location="http://domainname.net/";
}
else if(url="http://www.domainname.net/")
{
window.location="http://domainname.net/";
}

the domainname is samename with different extensions all are in the same & single server(cloud) with different site bindings.

It's working for a single conditional loop
if(url=="http://domainname.com/")
{
window.location="http://domainname.net/";
}

but i can't able to get that for else if conditions,it's just refreshing after redirecting to the target.

Please do the needful.

Awaiting your valuable reply.
Narendran N

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.