I was wondering how to change a url in javascript
for example if i wrote an address
www.google.ei
How would i get the script to change the address to
www.google.ie

Recommended Answers

All 2 Replies

It's either you create a function that will handle your specified URLs or you can just apply simple inline execution like this:

<a onclick="javascript: this.href = this.href.replace('ei', 'ie');" href="www.google.ei" >Changing URL with JavaScript!</a>

It's pretty easy, in your userscript put these lines:

var regExp = /google\.ei\//i;
if (regExp.test(window.location.href))
        window.location.href = "http://www.google.ie";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.