Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Skins, Themes, ...Skins, Themes, ...How do I get current DNN page name for javascript variable?How do I get current DNN page name for javascript variable?
Previous
 
Next
New Post
2/1/2018 4:43 PM
 

Hi, 
I am trying to assign the current DNN page name to a variable in javascript, but I cannot find the correct coding.
I searched the web but I only found this usage, but is doesn't work. 

<script type="text/javascript">
var tabName = <% =TabName %>;
</script>

I am using DNN PLATFORM v.09.01.01 and 4.6.NET FRAMEWORK

What would be the correct way to assign the current page name to a variable in javascript?

Thanks,
Craig

 
New Post
2/2/2018 3:02 PM
 

I think you should be able to use: TabController.CurrentPage.TabName

Also be sure to put quotes or apostrophe's around it.

<script type="text/javascript">
var tabName = '<% =TabController.CurrentPage.TabName %>';
</script>

 



Andrew Walker

Learn to make your own beer and wine at homeIf you enjoy making your own beer and/or wine - be sure to check out http://www.ForemostBrewing.com
 
New Post
2/6/2018 10:28 PM
 
Nope it didn't work. I am using document.title for now, but I really want to use PageName.

Here is my javascript that is currently working:
/* add active class to Mega-Menu item if Page Title matches data-linkname */
var tabName = document.title;
$('.megamenu .second-level-list li[data-pagename="' + tabName + '"]').addClass('active');
$('.megamenu .second-level-list li a[data-pagename="' + tabName + '"]').addClass('active');

Here is what I really want to use:
/* add active class to Mega-Menu item if Page Name matches data-linkname */
var tabName = '<% =TabName %>';
$('.megamenu .second-level-list li[data-pagename="' + tabName + '"]').addClass('active');
$('.megamenu .second-level-list li a[data-pagename="' + tabName + '"]').addClass('active');

I tried your suggestion but it didn't work.
var tabName = '<% =TabController.CurrentPage.TabName %>';

Any other ideas or ways to test it?

Thanks,
Craig
 
New Post
2/13/2018 8:38 PM
 

This works for me. Just tested in DNN Community 8.4.

<script language="javascript" type="text/javascript">

    jQuery(function ($) {

        var tabName = '<%= PortalSettings.ActiveTab.TabName %>';

        console.log(tabName );

    });

</script>

Result: the name of the current page is printed to the console.

 
New Post
2/13/2018 9:45 PM
 

If I use the code in a separate javascript file that is in a DnnJsInclude it does NOT work. <dnn:DnnJsInclude ID="DnnJsColsFunctions" runat="server" FilePath="assets/js/functions.js" PathNameAlias="SkinPath" ForceProvider="DnnFormBottomProvider" />. 

If I have the javascript directly in the skin ascx file it DOES work. Is there a way to make it work from inside a js file that is being included and not in the actual skin ascx file? 

Thanks,
Craig

 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Skins, Themes, ...Skins, Themes, ...How do I get current DNN page name for javascript variable?How do I get current DNN page name for javascript variable?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.

Content Layout

Subscribe to DNN Digest

Subscribe to DNN Digest

DNN Digest is our monthly email newsletter. It highlights news and content from around the DNN ecosystem, such as new modules and themes, messages from leadership, blog posts and notable tweets. Keep your finger on the pulse of the ecosystem by subscribing.  

What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out