javascript - How to get window URL after redirect? - Stack Overflow

var win = window.open('');console.log(window.location.pathname);loginHow to get pathname

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 badges
Add a ment  | 

2 Answers 2

Reset to default 2

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 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

相关推荐

  • javascript - How to get window URL after redirect? - Stack Overflow

    var win = window.open('');console.log(window.location.pathname);loginHow to get pathname

    14小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信