-1

I am working on a conditional () to trigger the document.getElementById("testchange") script. I need it to trigger only from the /eng/ folder onward not just the example.com/eng/ URL which is how its configurred now with the window.location.pathname == '/eng/'

if(localStorage.getItem('textSet2') && (window.location.pathname == '/eng/')) {
            document.getElementById("testchange").innerHTML = "Empieza Ya!";             
}

So what is the substitute for window.location.pathname == to trigger the script only for a specific folder name onward, or trigger the script for the example.com/eng/ folder and its URLs inside of the folder like example.com/eng/house.php and example.com/eng/cat.php and so on?

The window.location.pathname == '/eng/' only works for the example.com/eng/ URL not the URLs inside of it like example.com/eng/house.php, etc. So any ideas of a command to detect folder names and the URLs inside as well. If so how would it look like inside the script i have. Thanx a lot.

bonini81
  • 61
  • 7
  • 1
    possible duplicate of [How can I check if one string contains another substring?](http://stackoverflow.com/questions/1789945/how-can-i-check-if-one-string-contains-another-substring) – Ryan Sep 08 '15 at 21:36

1 Answers1

0

Use this :

var path = window.location.href;

if(path.indexOf('/eng/')>-1){
var myPath = path.substr(path.indexOf('/eng/'));
}

if(localStorage.getItem('textSet2') && (myPath == '/eng/')) {
        document.getElementById("testchange").innerHTML = "Empieza Ya!";             
}

window.location.href is used to get the full URL of a webpage.

Arjun
  • 1,261
  • 1
  • 11
  • 26
  • Hi this script does not seem to work for the intended purposes anyone see why? It looks pretty clear that it should, understand a bit the sintax. Of course i fixed the bug here, var myPath = path.substr(path.indexOf('/eng/'); there is a missing ) at the end other than that loox fine. Any ideas why? – bonini81 Sep 09 '15 at 00:43