user2348566
user2348566

Reputation: 15

Use Jquery to remove first URL in a double URL link

I am trying to remove the first url in a double url link such as:

http://somewebsite.com/something/#/###/#/http://someotherwebsite.com/

after a page loads. So afterwards, would look something like:

http://someotherwebsite.com/

Where # = numbers

Sometimes the first website is a .org or.net. I tried searching and tried ideas but never remove the first full link.

Upvotes: 0

Views: 227

Answers (3)

Rok Burgar
Rok Burgar

Reputation: 949

Try to extract information with url regex:

var matches = tmp.match(/^(https?\:\/\/[^\/?#]+)(?:[\/?#]|$)/i);

DEMO

Upvotes: 1

Adil Shaikh
Adil Shaikh

Reputation: 44740

str =  "http://" + (str.split('http://')[2]);

Demo --> http://jsfiddle.net/Em9SU/

Upvotes: 1

David Ziemann
David Ziemann

Reputation: 970

it's not pretty, but this will get you at least on the correct track:

links = 'http://somewebsite.com/something/#/###/#/http://someotherwebsite.com/'
links = links.split('http')
console.log(links[2])

that will give you the second link (removing the 'http', but from there you can just add it back on and do what you need. It's not pretty, but it doesn't sound like you are looking for an elegant solution

If you want to know more about the split() function, it basically splits (hence the name) a string based on an input (the 'http' in our case). From there you can just traverse through it or do whatever you want with the list.

Upvotes: 0

Related Questions