This question already has answers here:
How to remove the hash from window.location (URL) with JavaScript without page refresh?
(17 answers)
Closed 8 years ago.
This is my url:
http://example.com/index.php#motto
On page load remove #motto with Javascript.
try this: window.location.hash=""
$.fn.urlHash = function()
{
return window.location.hash.replace('#','');
};
$.urlHash();
Related
This question already has answers here:
How can I get query string values in JavaScript?
(73 answers)
Closed 4 years ago.
I have this URL https://localhost/test.html?view=1111&project=1000.
How would i write java script function to fetch the variable project..?
A cool trick is to split your URL with project= and take the second element :
const url = "https://localhost/test.html?view=1111&project=1000"
console.log( url.split("project=")[1] )
This question already has answers here:
JavaScript - Get Portion of URL Path
(6 answers)
Closed 8 years ago.
If the current url is: "https://stackoverflow.com/questions/ask"
What's a good way to just get: "questions/ask" ?
You could use
window.location.pathname.substring(1)
You would use window.location.pathname
console.log(window.location.pathname.substring(1));
This would output everything after the first /
This question already has answers here:
Get the current URL with JavaScript?
(28 answers)
Closed 8 years ago.
I have this js function
function twitterShare(){
window.open( 'http://twitter.com/intent/tweet?text='+$(".section-title h1").text() +'
'+window.location, "twitterWindow",
"height=380,width=660,resizable=0,toolbar=0,menubar=0,status=0,location=0,scrollbars=0")
return false;
}
When the twitter window opens it grabs the .section-title h1 class, but I need it to say something like this,
"Check this out here: http://currentwebsiteurl.com"
I need a text string then grab the url of the page.
Any help would be greatly appreciated.
window.location.href contains the current URL of the page.
So your function should look like this:
function twitterShare(){
window.open('http://twitter.com/intent/tweet?text=Check this out here: ' + window.location.href,
"twitterWindow", "height=380,width=660,resizable=0,toolbar=0,menubar=0,status=0,location=0,scrollbars=0")
return false;
}
You can use window.location.href. It holds the value of the current page you are on.
This question already has answers here:
Redirect faster with Greasemonkey (or similar userscript engine)?
(3 answers)
Closed 9 years ago.
i want to redirect from the first link to the other using javascript or jquery in greasemonkey
http://*.tumblr.com/post/*/*
http://$1.tumblr.com/image/$2
Use this regex
/^http:\/\/(.*).twitter.com\/post\/(.*)\/(.*)/g
Like this
var regexp = new RegExp(/^http:\/\/(.*).twitter.com\/post\/(.*)\/(.*)/g);
var results = regexp.exec(window.location.href);
To create your array, then you can
if(results){
window.location="http://"+results[1]+".twitter.com/image/"+results[2]+"/"+results[3];
}
To redirect
Live Version
This question already has answers here:
How can I get query string values in JavaScript?
(73 answers)
Closed 9 years ago.
Wondering if someone could help with out with creating a regex..
Basically, taking an iFrame's src, and seeing if it's from SoundCloud. If it is, return its id. For example:
var src = 'http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F85110490&auto_play=false&show_playcount=false&show_user=false&show_comments=false&buying=false&liking=false&sharing=false&show_artwork=false&color=00e7ff';
function soundcloudId(src) {
var p = /___________/;
return (src.match(p)) ? RegExp.$1 : false;
}
soundcloudId(src);
And as a result, it would run the "src" through the regex, and if a soundcloud link, would return 85110490. Otherwise, false.
Try this regex:
/http:\/\/w.soundcloud\.com\/.*%2Ftracks%2F([0-9A-F]+)/
Runnable example: http://jsfiddle.net/mYf6P/