var win = window.open('');
console.log(window.location.pathname); // /login
How to get pathname after /login page redirect me to other page?
Thanks in advance.
var win = window.open('http://example./login');
console.log(window.location.pathname); // /login
How to get pathname after /login page redirect me to other page?
Thanks in advance.
Share Improve this question asked Jul 11, 2014 at 9:11 owlowl 4,5094 gold badges26 silver badges28 bronze badges2 Answers
Reset to default 2You 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 pleted. 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./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.
What you want to achive is munication 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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745571186a4633690.html
评论列表(0条)