0

I have a Url which is like this. https://testOne.abcd.com/myOrders/OrderList/Order123.aspx

How do I get only Order123 ? I used window.location.href.split('/')[5].split('/')[1]

how do i set it dynamically?

TIA

1
  • Do you want to get or set the filename? Commented Jul 27, 2011 at 22:44

2 Answers 2

1

if you want to use substr string method..

var filename = url.substr(url.lastIndexOf('/')+1) // -> 'Order123.aspx'
var filename_noext = filename.substr(0, filename.lastIndexOf('.')) // -> 'Order123'
Sign up to request clarification or add additional context in comments.

Comments

0

If you want to get the file name, minus the extension, this will work.

var regex = /.*\/([^\/]+)\.aspx/;

var url = 'https://testOne.abcd.com/myOrders/OrderList/Order123.aspx'

var match = regex.exec(url);
var fileName = match[1];
alert(fileName);   // This will output "Order123"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.