What I want to do is use a variable with window.location.href.indexOf() This is my code right now, I want to be able to shorten it.  var urls  = [ 'https://www.example.com/'  ,'https://www.example2.com/'  ,'https://www.example3.com/'   ,'https://www.example4.com/' ,'https://www.example5.com/' ];    // if ((window.location.href.indexOf(""+urls+"") &gt; -1) Does not work if ( (window.location.href.indexOf("https://www.example.com/") &gt; -1) || (window.location.href.indexOf("https://www.example2.com/") &gt; -1) || (window.location.href.indexOf("https://www.example3.com/") &gt; -1) || (window.location.href.indexOf("https://www.example4.com/") &gt; -1) || (window.location.href.indexOf("https://www.example5.com/") &gt; -1)    ) { //do stuff  }   I've included what I've tried in the code but it doesn not work. javascript and jquery both work for me
717
What is the most concise and efficient way to find out if a JavaScript array contains a value? This is the only way I know to do it: function contains(a, obj) {     for (var i = 0; i &lt; a.length; i++) {         if (a[i] === obj) {             return true;         }     }     return false; }  Is there a better and more concise way to accomplish this?
81188
Just wondering if there is anything built-in to Javascript that can take a Form and return the query parameters, eg: "var1=value&amp;var2=value2&amp;arr[]=foo&amp;arr[]=bar..."  I've been wondering this for years.
88330
I've seen some people using void operator in their code. I have also seen this in href attributes: javascript:void(0) which doesn't seem any better than javascript:;  So, what is the justification of using the void operator?
33995
I am confused about hreflang="x-default".  I have a site in 2 languages. In each page I have a link to the page itself and a link to the same page in the other language. If I understand correctly, I have to put an x-default also. In my case it goes to the page "language". There the user can see two buttons to choose the language of the site.  The x-default link is the same on all pages and it is present in all of them.   &lt;link rel="alternate" hreflang="en" href="http://example.com/about" /&gt;  &lt;link rel="alternate" hreflang="fr" href="http://example.com/fr/about" /&gt; &lt;link rel="alternate" hreflang="x-default" href="http://example.com/language" /&gt;   I use Screaming Frog to detect possible errors. It says "Missing confirmation links in all the pages" when I see the details of the error. It makes reference only to the x-default link. I do not understand.  How to use the hreflang="x-default"?
2878
I want to use a PHP variable in JavaScript. How is it possible?
62985
I have the following data:  http://example1.com    anchor text 1     http://example2.com    anchor text 2 http://example3.com    anchor text 3       And I would like the output to be:  http://example1.com    anchor text 1    &lt;a href="http://example1.com"&gt;anchor text 1&lt;/a&gt; http://example2.com    anchor text 2    &lt;a href="http://example1.com"&gt;anchor text 2&lt;/a&gt; http://example3.com    anchor text 3    &lt;a href="http://example1.com"&gt;anchor text 3&lt;/a&gt;   I have tried getting the code to substitute cells A1 and B1 in cell C1 like this:  ="&lt;a href="A1"&gt;B1&lt;/a&gt;"   However, I'm getting errors because of the equal sign and double quotes in the HTML code. I have tried using single quotes to escape it, but still no luck.  Anyone know how to do this? Your help is highly appreciated.
7509
I try to write a simple Markdown parser in JavaScript. Therefore I want to check for the [link content][link id] syntax. I use the following code:  data = data.replace( /\[(.*?)\][ ]*\[([0-9]+)\]/g, '&lt;a href="$2"&gt;$1&lt;/a&gt;' );   It works well, but now I want to do this with a RegExp object. So I set up the following bit of code:  var r = new RegExp( '\[(.*?)\][ ]*\[([0-9]+)\]', 'g' ); data = data.replace( r, '&lt;a href="$2"&gt;$1&lt;/a&gt;' );   But it doesn't work. It even says that my regular expression (which works since the first example does a good job) is invalid:     unmatched ) in regular expression   I think it must have to do with some RegExp-object peculiarities I am not aware of. What am I doing wrong and how can the problem be solved?
70194
We have a custom javascript button on the quotes object in our org that has been working for several months that someone has noticed today is not working.    I'm not sure if there was an update that broke it or what day exactly it stopped working.  I'm hoping someone has an idea of where I can even begin to look.   Here's the code:   javascript:location.href= 'mailto:emailaddress@ourdomain.com?SUBJECT='+ escape("{!Quote.Name}")+' - '+ escape("{!Quote.Contact_s_Account__c}") + '&amp;BODY=Please convert ' + escape(location.href)+ ' into a proposal and send it to the email address on the quote.  Thanks!';   Using developer tools in chrome, I see this error after I click the javascript button:   presence: onFailure in event parser ={"status":-5,"statusText":""}page load happens value=true           umps1w4.salesforce.com/umps/UMPSWidget_184/js/dist/umps-min.js?cflag=184.36:14 presence: onFailure in event parser ={"status":-5,"statusText":""}page load happens value=true   I changed my code to something simple:   javascript:location.href= 'mailto:emailaddress@ourdomain.com?SUBJECT='hello'    and got this error in the developer tools in chrome:   Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.   This lead me to the conclusion that I'm having XSS issues.  I do remember a SF update not too long about about protecting against XSS issues.  I guess I'll have to figure out a different way to implement this functionality.
113029
I have on my website a lot JS, e.g.:  &lt;a href="#" class="slideshow-button clicked"&gt;Slideshow&lt;/a&gt;  &lt;a href="#" class="fullscreen-button clicked"&gt;Full Screen&lt;/a&gt;  When user click on that this not affect  "page per session" ? if I edit the HTML and add in a href e.g. example.com/something will it then affect "page per session"?
80302
&lt;div id="myDiv"&gt;      &lt;a&gt;...&lt;/a&gt;      &lt;a&gt;...&lt;/a&gt;      &lt;a&gt;...&lt;/a&gt;      &lt;a&gt;...&lt;/a&gt;      &lt;a&gt;...&lt;/a&gt;      &lt;a&gt;...&lt;/a&gt; &lt;/div&gt;   If you wanted to select the 2nd, 3rd and 4th a tags in the above example, how would you do that? The only thing I can think of is:  $("#myDiv a:eq(1), #myDiv a:eq(2), #myDiv a:eq(3)")   But that doesn't look to be very efficient or pretty. I guess you could also select ALL the as and then do run .each over them, but that could get very inefficient if there were a lot more as.
19595
I quite often see JavaScript with variables that start with a dollar sign. When/why would you choose to prefix a variable in this way?  (I'm not asking about $('p.foo') syntax that you see in jQuery and others, but normal variables like $name and $order)
96533
I have a list of URLs in a text file, for example,  http://url1 http://url2 http://url3   I wonder how to open them each in one tab in Firefox (or SeaMonkey), without the hassle of creating a new tab, copying into address bar and hitting return for  each URL?  My OS is Ubuntu 10.10. Both command line and GUI solutions are welcome.
105678
My code looks like this:  &lt;ul id="ulList"&gt;   &lt;li class="listClass" id="id1"&gt;&lt;a href="http://link1"&gt;Link 1&lt;/a&gt;&lt;/li&gt;   &lt;li class="listClass" id="id2"&gt;&lt;a href="http://link2"&gt;Link 2&lt;/a&gt;&lt;/li&gt;   &lt;li class="listClass" id="id3"&gt;&lt;a href="http://link3"&gt;Link 3&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;   Now I like to get the following:  All links as an array  All ids of li as an array  Can someone help me please?
19222
I can do an eval("something()"); to execute the code dynamically in JavaScript. Is there a way for me to do the same thing in C#?  An example of what I am trying to do is: I have an integer variable (say i) and I have multiple properties by the names: "Property1", "Property2", "Property3", etc. Now, I want to perform some operations on the " Propertyi " property depending on the value of i.   This is really simple with Javascript. Is there any way to do this with C#?
81334
I have a file with a list of URL's. I need to pass each URL from a bash script to be used in an AppleScript.    while read urls do      osascript -e \     'tell application "Safari"         tell window 1              tell current tab to open location "$urls"         end tell     end tell' done &lt;file.txt   This doesn't work. It passes the literal string $urls as the location to be opened in Safari. How can I pass the bash variable $urls to AppleScript?
106949
I'd love some other opinions on what's more efficient in this code. Basically in the following code, there's a setInterval loop and I need 4 requirements to be true before the code runs in the loop. So in v.1 I wrote an if statement checking all 4. Worked fine.  Then I switched to just using try/catch, with the code I want to execute sitting in try{}. The logic was that during each loop, an exception would be generated but suppressed for each invalid condition. On the final loop where all conditions are true, the code executes and clears the interval.  Either works. I like the try/catch method because there's less conditional code that I need to write and worry about breaking. But I'm worried that try/catch is really inefficient, especially in a setInterval() loop hitting at 100ms. What are some opinions of other bright minds here on SO?  Try/Catch  var intvar = setInterval(function(){ try{         clearInterval(intvar);      jQuery('#'+nav[pageid].t1+'&gt;a').replaceWith(jQuery('&lt;span&gt;'+jQuery('#'+nav[pageid].t1+'&gt;a').text()+'&lt;/span&gt;'));      //set display classes for nav     jQuery('#'+nav[pageid].t1).addClass('selected').find('#'+nav[pageid].t2).addClass('subselect'); //topnav     jQuery('#'+nav[pageid].t3).addClass('selected').find('#'+nav[pageid].t4).addClass('subselect'); //leftnav }catch(err){} },100);   IF Block  var intvar = setInterval(function(){  if(typeof jQuery == 'function' &amp;&amp; typeof nav == 'object' &amp;&amp; typeof pageid != 'undefined' &amp;&amp; typeof document.getElementById('leftnav') == 'object'){     clearInterval(intvar);     jQuery('#'+nav[pageid].t1+'&gt;a').replaceWith(jQuery('&lt;span&gt;'+jQuery('#'+nav[pageid].t1+'&gt;a').text()+'&lt;/span&gt;'));      //set display classes for nav     jQuery('#'+nav[pageid].t1).addClass('selected').find('#'+nav[pageid].t2).addClass('subselect'); //topnav     jQuery('#'+nav[pageid].t3).addClass('selected').find('#'+nav[pageid].t4).addClass('subselect'); //leftnav }  },100);
66978
I have got a problem with JavaScript. I want to add a drop down list control with a link as Value of it. After it will be choosen and clicked button it schould redirect me to chosen link. I tried this code from this Article:       &lt;select name="list" id="list" accesskey="target"&gt;     &lt;option value='none' selected&gt;Choose a theme&lt;/option&gt;     &lt;option value="index.html"&gt;Theme 1&lt;/option&gt;     &lt;option value="theme2.html"&gt;Theme 2&lt;/option&gt;     &lt;option value="theme3.html"&gt;Theme 3&lt;/option&gt; &lt;select&gt; &lt;input type=button value="Go" onclick="goToNewPage()" /&gt;  &lt;script type="text/javascript"&gt; function goToNewPage() {     var url = document.getElementById('list').value;     if(url != 'none') {         window.location = url;     } }     but when I tried to add by the script, or by html on site, or by designer its erase me that sort of text:  &lt;input type=button value="Go" onclick="goToNewPage()" /&gt;   It's live only:  &lt;input type=button value="Go" /&gt;