Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Load css if specified text not present

    I'm trying to create/find a script that will do the following:
    -load a css file regardless of any conditions.
    -do not load the css file if a certain text is present in a specified html div tag.

    i know this is done with a if/else state like this:
    Code:
    if (condition)
      {
      code to be executed if condition is true
      }
    else
      {
      code to be executed if condition is not true
      }
    but I do not know how to add the condition for the variable text and to specify the css file.

    I want the javascript to ignore loading the css if a div tag like this:
    Code:
    <div class="menu-opener"><a class="gwt-Anchor" href="javascript:">Text1<img src=..//img.jpg"></a></div>
    contains the word Text1, or any other I specify.
    Else, if any other text inside the div, the css should load normally.

    I believe this is not difficult for a js knower and I would be very grateful for a solution.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by ccristian View Post
    I'm trying to create/find a script that will do the following:
    -load a css file regardless of any conditions.
    -do not load the css file if a certain text is present in a specified html div tag
    AFAIK it is not possible. The CSS file should be loaded within the HEAD section (or at least before any element from BODY is loaded), or any HTML DIV element is placed below the HEAD, in the BODY section. So that you can not turn back to load (or, even less possible, to unload) something in the HEAD following a condition which depends on a value written in the BODY.

    After all, your aim sounds illogical to me. Can you detail your problem? Why do you need that? Maybe we could find another approach, as the one you want is impossible.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm trying to find a simple solution of hiding some information from all the users, except a few selected ones. While loading another css file is not a perfect one, it is sufficient for what i need.
    so it should be, in mind, something like:

    if (div contains the given text (user name - any of the user names given) )
    {
    nothing happens
    }
    else
    {
    load css
    }
    poate te pricepi tu (maybe you can find a solution). thank you very much.

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,441
    Thanks
    23
    Thanked 630 Times in 629 Posts
    Should be able to do this in php.
    Since the "if a certain text is present in a specified html div tag" has to be specified in the html you could add a php after the text that calls a function to "include" or not the css file.

    Additional:
    user name may come from the login and exists in the DB. You can add the include or not to the database.

    ie:
    query on user name -> Find not_include column -> else include. This makes the css subject to the user name.

    poate te pricepi tu => Nice to have Im Translator installed.

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by ccristian View Post
    I'm trying to find a simple solution of hiding some information from all the users, except a few selected ones.
    That is definitely a job for a server-side code. Which kind of "selected" users? Registered in a DB? Or how?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Tags for this Thread

    Posting Permissions

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