• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

var location = window.location.href;

Community Beginner ,
Aug 21, 2015 Aug 21, 2015

Copy link to clipboard

Copied

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>

Views

3.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Aug 26, 2015 Aug 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==='

...

Votes

Translate

Translate
Advocate ,
Aug 21, 2015 Aug 21, 2015

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 24, 2015 Aug 24, 2015

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 24, 2015 Aug 24, 2015

Copy link to clipboard

Copied

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..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 25, 2015 Aug 25, 2015

Copy link to clipboard

Copied

I would recommend asking this over at http://stackoverflow.com/

This is not a Coldfusion issue but a simple javascript knowledge / documentation issue.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 26, 2015 Aug 26, 2015

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation