Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6935651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:07:50+00:00 2026-05-27T12:07:50+00:00

slightly related to this question here . My problem: I am writing a bit

  • 0

slightly related to this question here.

My problem:

I am writing a bit of script that will read the referring URL of a page and check to see where it comes from i.e. Google, Bing etc. Now I know I can just do a document.referrer.search('google'); but I don’t want to do it like this as it makes sense to read the values from an array or object. I’ve created an object which has the term that I am searching for and the property name as follows:

var searchProviders = {
  "google": "google.com",
  "bing": "bing.com",
  "msn": "search.msn",
  "yahoo": "yahoo.co",
  "mywebsearch": "mywebsearch.com",
  "aol": "search.aol.co",
  "baidu": "baidu.co",
  "yandex": "yandex.com"
};

Now, what I want to know is can I iterate through this object and do a document.referrer.search(searchProviders[0]) and then return the property name? so for example if it contains, google.com I want it to return google? The reason I want this term to be returned (and not the search term) is because this value needs to be used later on.

I remember reading in the question posted above that you can only use a foreachstatement to iterate through an object – is there another way for me to do this? Of course if I could use a foreach statement, but I want the statement to break if it finds the correct value (hence why I want to use an if).

So I’m a little stuck as to what’s the best approach. Any help would be appreciated, hope I’ve explained everything well – if not please tell me and I will update my question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:07:51+00:00Added an answer on May 27, 2026 at 12:07 pm

    You should be able to iterate like this:

    for (var key in searchProviders) {
        if(!searchProviders.hasOwnProperty(key)) { continue; }
        var URL = searchProviders[key];
        if (document.referrer === URL) {
          return key;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Slightly related to this question , but you don't really need to read that.
I realize that this question is slightly server related and could be posted on
This is slightly related to the question asked here yet the answer does not
Although slightly related to a previous question, it is different. How secure is this
not sure if this question should be here or in serverfault, but it's java-related
This is perhaps related to this question , but I have slightly more information.
[Disclosure: This question is slightly related to my previous question .] As you can
Slightly related question to this one and this one . Basically, I would like
Slightly related to my other question : What is the difference between the following:
Sorry for the slightly noobish question, as I am writing my first rails app.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.