Not sure why indexOf() method is not working with my conditional in JavaScript

I have a function which is going through links in a document to determine if a certain pathname is present. Essentially if it is present target _self is set. If not I'd like to have the target attribute set to _blank

/*   These are properties of a larger function,   I am just trying to zero in on the problems.  */        var URLS = {              'foo': '',              'bar': '',              'yay': '',          },            publicAPI;        function getURL() {          for (var i = 0; i < arguments.length; i++) {              return URLS[arguments[i]];          }      }    for (var i = 0, len = arguments.length; i < len; i++) {      url = getURL(arguments[i]);      for (var j = 0, jlen = container_links.length; j < jlen; j++) {      link = container_links[j];          if (link.href.indexOf(url) !== -1) {              parser = document.createElement('a');              parser.href = link.href;                newPathName = parser.pathname;              link.setAttribute('target', '_self');               if (|District|Division|National/) !== -1) {                newPathName = newPathName.split('/').pop();                newstr = newPathName;             } else {                newstr = newPathName;               }                link.href = newstr;          } else {              link.setAttribute('target', '_blank');          }                 }  }

What is bedeviling me is this:

if (link.href.indexOf(url) !== -1) { 

Shouldn't that be the key? if that url is not equal to -1 that means it's a match so link.setAttribute('target', '_self'); should be set to the a tag. And if it is equal to -1 link.setAttribute('target', '_blank');


Category: javascript Time: 2016-07-28 Views: 0
Tags: javascript

Related post

  • I'm not sure why my shape is not moving 2013-10-13

    So I am trying to teach my self how to my develop games with java by cloning older games. At the moment I am cloning Pong, and I can not figure out why my paddle is not moving. The move method should be updating the player paddle's position every fra

  • Not sure why React can't render DIV ? 2016-01-17

    After researching this issue around the clocks, I am not sure it doesn't allow to work with ReactDOM.render, I get error message regarding <DIV> with webpack + babel which couldn't understand JSX syntax. Package.json "devDependencies": { &

  • WordPress filtering utm_ GET variables from url unless logged in as admin, not sure why? 2013-10-31

    So I am having an issue where I can't pull variables such as unless I am logged in as admin or editor. When logged out and just a regular users I can't grab any variables which start in utm_ such as utm_campaign. Howe

  • Not sure why my loop is taking quite long to execute, is it due to the size of the data? 2016-01-19

    I have a dataset that is composed of (1069 x 38742), I want to remove all the 3rd columns of the matrix and so I have written a for loop to get this done. The code is as follows: ` dataTS1 = rand(1069,38742) for i = 1:12914 dataTS1(:,3*i) = []; end`

  • Why Execute method is not called? 2012-02-29

    I have created custom timer job and successfully deploy it into SP. I see this timer job and feature on the lists. Job is being called every 10 minutes with status "succeeded". Issue is that Execute method is not being called. This is part of my

  • Error with std::bad_alloc() after 3-4 runs of program, not sure why 2016-07-21

    This is code for a war card game. After running it for a number of times (varies each time), it throws a std::bad_alloc() error, and I'm not sure why. Card.h and deck.h are fine, but if this code looks good I will post them if needed. #ifndef WAR_H #

  • Why won't geolocation plugin work with phonegap? 2016-01-23

    Been trying to get the geolocation to work for far too long now. The console is giving me the following errors: Coordinates.js:69 Uncaught ReferenceError: module is not defined(anonymous function) @ Coordinates.js:69 geolocation.js:24 Uncaught Refere

  • Why won't biber-biblatex work with memoir? 2015-03-13

    Why won't biber-biblatex work with memoir? Seems that this is a longstanding issue, but I have not discovered any reliable resolution. In this mwe I get errors (i'm summarizing) like undefined refs and citations, cannot find .bib file, biber didn't f

  • Installation of Active Directory on separate VM from DNS does not entierly work - not sure why 2013-10-23

    Not sure what I am doing wrong here. I have a moderately midrange server (16 cores, 2Ghz, 32GB ECC REG RAM, 6TB storage, nothing too extreme) where I am running Hyper-V (Server 2012 R2 Enterprise) in order to provision virtual machines. So why an AD

  • Not sure why flex-grow: 1 isn't working in my column layout 2016-02-07

    I am trying to have the views-cntnr take up any space not used by views-cntnr and menubar divs. To achieve this, I have a flex display set to column direction. Then I set the flex-grow property for the views-cntnr to 1. Doesn't appear to be doing any

  • Simple Button in javascript isn't working, tried hosts of things, not sure why 2016-01-26

    Now first, i'm not even sure if you can do this; but with my limited knowledge of functions, I wanted to create a button that will display both an object in the console and on the document. I figured, it would be easier to try to run in the console f

  • Slow MySQL query, not sure why 2012-09-21

    I'm working with an intranet application for property tax collection, and I've hit a snag. The following view runs much slower than I'd expect: create or replace view propertytaxessub0 as select propertysid, sum(amount) as totaltax from taxes group b

  • Not sure why my custom post meta field isn't saving 2013-06-08

    I'm having trouble getting my custom post meta field to save and I'm not quite sure why. I was following the tutorial located at and had some pretty big difficulty de-coding t

  • Getting "negotiation: discovered file(s) matching request:" error not sure why 2013-10-25

    I'm currently trying to transfer a site to a new server running Ubuntu 12.10. The site worked fine on the old server, however, the new server is giving me some problems. When I access the site, I get a white page. After viewing the source, I see that

  • My CRC8 is dysfunctional and I'm not sure why! 2013-12-12

    So I'm interfacing an arduino with a Melexis temperature sensor, and it's going okay--aside from the fact that I can't seem to get the CRC check to work. I've gotten read operations to complete successfully (although my software ignores the packet er

  • scp is returning a permissions denied, not sure why? 2010-11-27

    scp -i ~/.ssh/my_id_rsa -P 30000 some_file.gz [email protected]:/home/sshuser/ And it returned: scp:/some_file.gz: Permission denied The rsa key file is the same file I use to connect via SSH (along with the port # and username and i.p) Does anything s

  • Git autocomplete is asking for a password, not sure why 2012-10-31

    I'm running into an issue with autocomplete using git... I am using ubuntu 12.10 and when I perform the following keystrokes g i t Space Bar Tab I am presented with the error Pseudo-terminal will not be allocated because stdin is not a terminal. and

  • My attempt to local redefine a command is failing and not sure why 2013-09-12

    I want to decorate some text and then reprint it undecorated. This is the code that I was using to do this. \documentclass{article} \usepackage{xcolor} \makeatletter \newcommand{\@aeformatcontent}[1]{\parbox[t]{5in}{\emph{#1}}} \newcommand{\aeformatc

  • Why won't Time Machine work with a drive connected to an Airport Extreme? 2012-08-03

    Is there any technical limitation or engineering reason that could possibly be behind the inability to RELIABLY use a connected USB drive with Airport Extreme for Time Machine? --------------Solutions------------- Not a complete answer, but this docu

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 2.940 (s). 13 q(s)