Skip to main content
Participating Frequently
August 21, 2015
Answered

var location = window.location.href;

  • August 21, 2015
  • 2 replies
  • 3577 views

Actually I am trying to search whether a particular word exists in URL and trying with below code  in in a .cfm file.

It works fine in html page but not working in coldfusion.Can someone help me how to resolve this issue

<script type="text/javascript">

var location = window.location.href;
if (location .indexOf("search_Text") > -1)
{
//do stuff
}
else
{
//do stuff
}
</script>

    This topic has been closed for replies.
    Correct answer Steve Sommers

    From what I gather this is not a ColdFusion question so I'm not sure why you have two result for coldfusion vs. html. Two things:

    1. I've had issues with some browsers using window.location and have found document.location to be more reliable.
    2. I've run into descrepancies with some browsers (IE) between document.location and document.location.href. To get around this I use logic like this:

       this.settings.self=document.location;

       ...

       if(this.settings.self.href && (typeof this.settings.self.href==='string')) {

        // set to string property (IE fix)

        this.settings.self = this.settings.self.href;

       }

    (the above was a snippet from a plug-in I wrote -- "this.settings" should be adjusted to your needs)

    Hope one or both these help.

    2 replies

    Steve SommersCorrect answer
    Legend
    August 26, 2015

    From what I gather this is not a ColdFusion question so I'm not sure why you have two result for coldfusion vs. html. Two things:

    1. I've had issues with some browsers using window.location and have found document.location to be more reliable.
    2. I've run into descrepancies with some browsers (IE) between document.location and document.location.href. To get around this I use logic like this:

       this.settings.self=document.location;

       ...

       if(this.settings.self.href && (typeof this.settings.self.href==='string')) {

        // set to string property (IE fix)

        this.settings.self = this.settings.self.href;

       }

    (the above was a snippet from a plug-in I wrote -- "this.settings" should be adjusted to your needs)

    Hope one or both these help.

    Inspiring
    August 21, 2015

    Why is it not working? Are you getting an error? What happens?, what are you expecting to happen?

    This is not CFML and wont be be Coldfusion giving you problem with this unless you haven't configured your server correctly.

    Participating Frequently
    August 24, 2015

    Let me explain my problem in details.

    Let as consider I am having a url http://ip/123/index.cfm?module=controller.list#Tab


    In a screen I have four tab..If I click on 1st tab the url will be http://ip/123/index.cfm?module=controller.list#Tab_1

    same way  If I click on 2nd tab the url will be http://ip/123/index.cfm?module=controller.list#Tab_2


    now through javascript I want to check if Tab_1 in url need to do stuff A\

    if in url the value is Tab_2 then need to do stuff B..

    Please help me how to carryout this functionality

    Participating Frequently
    August 24, 2015

    I am not getting any error  when I am running above code.

    <script type="text/javascript">

    var location = window.location.href;
    if (location .indexOf("Tab_1") > -1)
    {
    //do stuff A
    }
    else
    {
    //do stuff B
    }
    </script>

    But in all scenario stuff 2 is executing..