Reputation: 4461
var win = window.open('http://example.com/login');
console.log(window.location.pathname); // /login
How to get pathname after /login page redirect me to other page?
Thanks in advance.
Upvotes: 1
Views: 10337
Reputation: 4718
You can use win
not window
to retrieve it.
console.log(win.location.pathname);
Please note that you can retrieve the path only after the redirection is completed. So I guess you can get the path data by using timer or some other events ( e.g. click ) like below:
<script>
var win = window.open('http://example.com/login');
function showChildURL(){
alert(win.location.href);
}
</script>
<a href="javascript:showChildURL();">showChildURL</a>
index.html
<html>
<body>
<script language="javaScript">
var win = window.open('1.html');
function showChildURL(){
alert(win.location.pathname);
}
</script>
<a href="javascript:showChildURL();">showChildURL</a>
</body>
</html>
1.html
<html>
<head>
<meta http-equiv="refresh" content="0;URL='2.html'" />
</head>
<body>
<p>This page will be redirected to 2.html</p>
</body>
</html>
2.html
<html>
<body>
This is 2.html
</body>
</html>
Hope this helps.
Upvotes: 2
Reputation: 471
What you want to achive is communication between browser tabs/windows. You'll have to use cookie or localStorage to notify your main window about redirected url. Take a look at LocalConnection.
Upvotes: 0