Comparing URLS in javascript [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Whats another way to compare URLs? This is not working. Its been a really long while since i've coded
var myURL =
(window.location.href="http://randbox.blogspot.com/2014/01/test-0.html");
if ( alert(document.URL) == myURL ) {

var myURL =
(window.location.href="http://randbox.blogspot.com/2014/01/test-0.html");
if ( document.URL == myURL ) {
Remove the alert() function. It's not comparable to a variable, so it will return false.
If it still doesn't work, document.URL might not be what you're wanting, or the string is incorrect, or maybe both are wrong.

Related

javascript regex to get the content of a string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a string
var str="[a54hy 8:45pm],[f57gh 9:20]"
i need to get
[f57gh 9:20pm]
I don't want to use split since the string length can be anything
This worked for me. where id is f57gh
var re='\\['+id + '([a-z0-9: ]+)\\]';
var rematch=RegExp(re,'g');
var mydata=str.match(rematch);
alert(mydata); //[f57gh 9:11am]

Find an element that has a text value of 0? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I need to find an element that's text value is 0.
I do:
var d = $('.content').find('div');
if(d.text().length === 0){
//do something
}
Is there a way to put the above logic in the selector?
I've tried:
var d = $('.content').find('div:empty');
But no luck as the div may have other empty html tags in.
Use a filter
var elems = $('.content').find('div').filter(function() { return $(this).text() == 0 });

regular expression in javascript checking for "asdasd<something>asdsada" [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
how would I check for string
<something> in var string = "some chars <something> somechars"
You can use String.match():
var res = string.match(/<something>/g); // ["<something>"]
If there is no match, the value of res will be null. See example on JSFiddle.

How to "parse" js twice? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
The following Code should output:
txt1txt2txt3...
var result ='';
var help='';
var a_1 = "txt1";
var a_2 = "txt2";
...
for (i=1;i<=100;i++)
{
help = 'a_' + i; // This line should be "parsed twice" !
result = result + help;
document.write(result);
}
Of course, I can avoid this by using the if-, or case-function for each "a_ i",
but this would make my js file very big.
So is there a way to parse this "help line" twice with js?
I asume, I could do it with including one js file in another, but I dont like this way?
No PHP , because the code should work clientside
Better to use an array.
eval() is the function for "double parsing" (but could be really dangerous !)

Regex param from url in javascript [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Can you help me please to get some param from an URL.
Url should be the form : http.www.lolilol.com/gallery/Param1/Param2/Param3/
I need to get Param1, Param2 and Param3.
A simple solution :
var params = document.location.pathname.split('/').slice(2);
This gives you the array ["Param1", "Param2", "Param3"]
The regex would be http://www\.lolilol\.com/gallery/(.*)/(.*)/(.*)/ assuming you meant http://www.lolilol.com/gallery/Param1/Param2/Param3/

Categories