SitePoint Sponsor

User Tag List

Results 1 to 14 of 14

Thread: If URL statment

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    If URL statment

    Hey everyone,

    Im currently trying to place a social media panel in my website (which i have done via my main template) however im having an issue trying to make sure it dosnt display on certain pages - ie login page, order page etc...

    The code below is what i have and i cant even get it to work on a single URL - can someone help / tell me how i cna get this to work on a single link then how i can add multiple url's ?

    HTML Code:
    <script type="text/javascript">
    
                if (URL is "http://local.ardmoor.co.uk:1460/Login")]
                            { 
                                 "<div class="social_right" style='display:none;'></div>"; 
                            }
                            else
                            { 
                                 "
    
                    <div class="social_right">
    
                    Share Ardmoor with friends -
                    <span class='st_sharethis' >&nbsp;</span>
                    <span class='st_facebook' >&nbsp;</span>
                    <span class='st_twitter' >&nbsp;</span>
                    <span class='st_linkedin' >&nbsp;</span>
                    <span class='st_email' >&nbsp;</span><script type="text/javascript">                                         var switchTo5x = true;</script>
                    <script type="text/javascript" src="https://ws.sharethis.com/button/buttons.js"></script>
                    <script type="text/javascript">    stLight.options({ publisher: "d8ab5791-00df-44e3-8d5f-939f11125f37", onhover: false });</script>
    
                     </div>   "; ; 
                            }
    </script>  
    
            
    
    



    Many thanks

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,389
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Hi A.mckenzie93,

    Are your pages static html, or are they generated on the server by PHP or something?

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The pages are generated via PHP but the main template is pushed out onto all pages. i have set up the div section for the content i need and it displays correctly on all pages - just im having an issue making sure it Dosnt display on the pages i dont want it to!

    Im still learning alot each day about web development but PHP is not something i know anything about, i know about HTML and CSS, the template is a .ascx

  4. #4
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,389
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by A.mckenzie93 View Post
    the template is a .ascx
    This sounds like ASP.NET rather than PHP.

    The best solution would be to prevent the panel being added when the page is generated on the server. You can do it in JS, but it's not ideal as the panel obviously won't be hidden if the user has JS disabled, and may briefly appear on screen as the page is loaded, before the JS kicks in to hide it.

    Having said that, if you're not able to change things on the server side for some reason, I can show you how to do it with JS. Do you use jQuery on the site?

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can tell i dont know much when it comes to PHP or ASP.Net!

    I believe i can use Jquery on the site yes, i can link in the file and if you show me the code this would be very helpful!

  6. #6
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,389
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    On second thoughts, don't worry about jQuery, we can do it without:
    HTML Code:
    <script>
    (function(){
        var urls = [
            '/login',
            '/order'
        ];
    
        for (var i=0; i < urls.length; i++) {
            if (window.location.pathname === urls[i]) {
                document.getElementById('hideMe').style.display = 'none';
            }
        }
    })();
    </script>
    Add this script at the bottom of your page (before the closing </body> tag), and give the div that you want to hide an ID (I've used hideMe in the example above). You can add more pages by adding the url to the urls array (note: don't add the domain name, just everything from the first forward slash onwards).

    This should be compatible with older versions of IE too, but I've not tested it. As I said before, it's not the best way to do it, but it should get you out of a fix.

  7. #7
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok i think there might be an issue with some of the things im working on and this code.

    All of the template .ascx dont have any body tags - so iv just placed this at the bottom of the template and it still dosnt hide the div.

    As well as this i changed the Div from a class to an id.

    here is the full page of code i am working on ( word of warning there is alot - the script is at the bottom and the div is mid way through roughly line 70+

    thanks for your on going support!


    HTML Code:
    <%@ Control Language="C#" AutoEventWireup="true" Inherits="InforgenWebProject.Web.Public.UserControls.Login" %>
    
    <%@ Import Namespace="InforgenWebProject.Common"%>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Import Namespace="InforgenPseudoMVC" %>
    <%@ Register TagPrefix="Control" TagName="ShoppingBasket" Src="ShoppingBasketControl.ascx" %>
    <%@ Register TagPrefix="Control" TagName="ShowIncVatToggle" Src="/usercontrols/ShowIncVatToggle.ascx" %>
    <%@ Register TagPrefix="Control" TagName="DeliveryCountrySelect" Src="/usercontrols/DeliveryCountrySelect.ascx" %>
    <%@ Register TagPrefix="Control" TagName="Login" Src="LoginControl.ascx" %>
    
    
    <div class="logo span-8 clearfix">
        <a href="/"><img src="/public/wso/images/ArdMoor/ArdMoor_logo.gif" alt="ArdMoor Ltd" /></a>
    </div>
    <div class="last span-16">
        <div class="headerMenu clearfix">
    	    
            <div class="telNo">
                <span><%= Html.StaticText("TelNo") %></span>
            </div>
            
    		<div class="accountLinks">
    			<Control:ContentDisplay ID="ContentDsiplayHeaderNavigation" SlotName="HeaderNavigation" runat="server" />
    			<Control:Login ID="Login" runat="server" />
            </div>
    		
        </div>               
        <div class="HeaderSecondRow clearfix">		
    		<div class="HeaderDeliverySelect">
    			<Control:DeliveryCountrySelect ID="BasketDeliveryCountry" runat="server" />							
    		</div>	
            <div class="HeaderVATToggle">
    			<Control:ShowIncVatToggle ID="HeaderPriceToggle" runat="server" />             			
            </div>	
    			
    		<div id="mini-basket" class="widget">
    			<Control:ShoppingBasket ID="Basket" runat="server" />
    		</div> 
        </div>  
    </div>
    <div class="menu clearfix">
        <a href="/" title="Go to Home Page" class="homeLink">
            <img src="/public/wso/images/ArdMoor/homeIcon.png" alt="Home" /></a>
        <Control:ContentDisplay ID="ContentDisplayMainNavigation" SlotName="MainNavigation"
            runat="server" />
    </div>
    
    <div class="subHeader clearfix">
        <span class="span-8 subHeaderSubText1"><%= Html.StaticText("DeliveryArdMoor") %></span>
        <span class="span-10 subHeaderSubText2"><%= Html.StaticText("SubHeadingTextArdMoor")%></span>
        <div class="quicksearch span-6 last">
        <%= Html.BeginForm(SiteUrlLinks.Search.Area, SiteUrlLinks.Search.Controller, HtmlHelper.NoAction, FormMethod.Post)%>
        <% Html.RemoveClass("search"); %>
            <div class="searchback clearfix">
                <label for="header-search" class="offscreen">
                    Search</label>
                    <div class="searchform span-6 last">
                        <input type="text" value="<%= Html.StaticText("Search")%>" name="site_search" id="site_search" class="searchinputcontrol" />
                        <input type="submit" class="searchbutton" alt="" name="add" value="GO" />
                    </div>
            
            </div>
        <%=HtmlHelper.EndForm()%>
        </div>
    </div>
    <div class="BreadCrumbs clearfix">
        <div class="span-24 last">
    
    
       
    
            <div id="social_right">
    
                    Share Ardmoor with friends -
                    <span class='st_sharethis' >&nbsp;</span>
                    <span class='st_facebook' >&nbsp;</span>
                    <span class='st_twitter' >&nbsp;</span>
                    <span class='st_linkedin' >&nbsp;</span>
                    <span class='st_email' >&nbsp;</span><script type="text/javascript">                                                         var switchTo5x = true;</script>
                    <script type="text/javascript" src="https://ws.sharethis.com/button/buttons.js"></script>
                    <script type="text/javascript">                    stLight.options({ publisher: "d8ab5791-00df-44e3-8d5f-939f11125f37", onhover: false });</script>
    
            </div> 
    
    
    
    
    
    
    
    
        <ul>
        <li class="you-are-in"><%=Html.StaticText("You are here:") %></li>
            <% if (ViewData.ContainsKey("Breadcrumbs"))
            {%>
                <% foreach (string breadcrumb in ViewData["Breadcrumbs"] as IEnumerable<string>)
                {
                    string[] breadcrumbParts = breadcrumb.Split(',');
                    string path = breadcrumbParts[0].Trim();
                    string name = breadcrumbParts[1].Trim();
                %>
                    <li><a href="<%= path %>"><%= name %></a><span class="separator"><%= Html.StaticText("BreadcrumbSeparator") %></span></li>
            <%
                }
            } else {%>
                    <li><a href="/">Home</a></li>
            <%}%>
        </ul>
        </div>      
    </div>
    
    
    <!-- START hide div section social media icons -->
        <script>
            (function () {
                var urls = [
                '/login',
                '/order'
            ];
                for (var i = 0; i < urls.length; i++) {
                    if (window.location.pathname === urls[i]) {
                        document.getElementById('social_right').style.display = 'none';
                    }
                }
            })();
        </script>
    <!-- END hide div section social media icons -->

  8. #8
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,389
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by A.mckenzie93 View Post
    All of the template .ascx dont have any body tags
    I'm a little confused now.. from your earlier posts I'd assumed you were only able to edit some kind of main page template, which is why you wanted to put code there to hide the social media div on certain pages. But from what you're saying now, it sounds like you can edit the templates for individual pages, is that right? If so, why not just add the div only to the pages where you need it?

  9. #9
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is technically the Header template which deals with all the .. well header stuff for the website - the social media icons are to be placed in there but not shown on certain pages that use this template. so its some form of a main template ( by that i mean its used on a majority of pages but not actually THE main template - sorry for my bad description )

  10. #10
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,389
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Ah OK, no worries, that makes sense now.. so what happens when you load the page now? Do you get any JS errors in the browser console?

  11. #11
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I take this all back! iv just had a dummy moment!

    '/login',
    '/order',
    '/order/basket'

    I had been loading the basket page and realized i didn't add it to the list!

    This is fantastic, thank you very much for your time and help on this fretburner!

  12. #12
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fretburner - next question!

    Is there a way of using this but in reverse? i want a div to only display on one page but in order to do so i need to place it on the template that is used across many pages.

    So if page = Myaccount {
    Show Div
    }
    Else
    {
    Dont show Div
    }

  13. #13
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,389
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Yeah that's quite simple to do - set your div to be hidden by default, and then change this line:
    Code JavaScript:
    //Original line:
    document.getElementById('social_right').style.display = 'none';
     
    //Replace with:
    document.getElementById('social_right').style.display = 'block';

  14. #14
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fantastic, thanks again Fretburner!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •