<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>js - WP2X</title> <atom:link href="https://wp2x.com/tag/js/feed/" rel="self" type="application/rss+xml" /><link>https://wp2x.com</link> <description>We can help your Wordpress faster</description> <lastBuildDate>Tue, 16 Sep 2014 14:16:30 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod> hourly </sy:updatePeriod> <sy:updateFrequency> 1 </sy:updateFrequency> <generator>https://wordpress.org/?v=5.6.16</generator> <item><title>How to get Current URL in Javascript?</title><link>https://wp2x.com/get-current-url-javascript/</link> <dc:creator><![CDATA[david]]></dc:creator> <pubDate>Wed, 07 May 2014 22:47:33 +0000</pubDate> <category><![CDATA[HTML/JavaScript/CSS]]></category> <category><![CDATA[Wordpress Tips]]></category> <category><![CDATA[html]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[js]]></category> <category><![CDATA[wordpress tips]]></category> <guid
isPermaLink="false">http://wp2x.com/?p=205</guid><description><![CDATA[<p>When develop a wordpress plugin or work in wordpress theme, I usually meet the problem with getting URL in javascript code. The problem come is I want to get current URL of current page because not all situation we can pass the current URL from PHP code. That &#8216;s why I decide to share this ...</p><p>The post <a
rel="nofollow" href="https://wp2x.com/get-current-url-javascript/">How to get Current URL in Javascript?</a> appeared first on <a
rel="nofollow" href="https://wp2x.com">WP2X</a>.</p> ]]></description> <content:encoded><![CDATA[<p>When develop a wordpress plugin or work in wordpress theme, I usually meet the problem with getting URL in javascript code. The problem come is I want to get current URL of current page because not all situation we can pass the current URL from PHP code. That &#8216;s why I decide to share this tips to you to save our time.<span
id="more-205"></span></p><p>It &#8216;s quite easy, just following this code</p><pre class="lang:js decode:true ">var currentPageUrl = "";
if (typeof this.href === "undefined") {
currentPageUrl = document.location.toString().toLowerCase();
}
else {
currentPageUrl = this.href.toString().toLowerCase();
}</pre><p>&nbsp;</p><p>You may want to get it as a stand-alone function to put it in your javascript library, then let &#8216;s define it as blow:</p><pre class="lang:js decode:true ">function getCurrentURL(){
var currentPageUrl = "";
if (typeof this.href === "undefined") {
currentPageUrl = document.location.toString().toLowerCase();
}
else {
currentPageUrl = this.href.toString().toLowerCase();
}
return currentPageUrl;
}</pre><p>&nbsp;</p><p>Now every time you want to get current URL, you just need to call <strong>getCurrentURL()</strong>. It &#8216;s quite easy to <strong>get current URL in javascritp</strong>! :).</p><p>Thanks for your visit and welcome your comment!</p><p>The post <a
rel="nofollow" href="https://wp2x.com/get-current-url-javascript/">How to get Current URL in Javascript?</a> appeared first on <a
rel="nofollow" href="https://wp2x.com">WP2X</a>.</p> ]]></content:encoded> </item> </channel> </rss>