开发者

get iframe redirection url in javascript

开发者 https://www.devze.com 2023-03-16 06:40 出处:网络
i am doing an iframe request to a page on my backend server. the page does a redirect and returns the same url as that which is requested but also appends a query string. how can i get the returned ur

i am doing an iframe request to a page on my backend server. the page does a redirect and returns the same url as that which is requested but also appends a query string. how can i get the returned url and query string? my ajax class looks like this:

var ajax =
{
  send: function(urlstring)
  {
    if(!this.ifram)
    {
     this.ifram = document.create开发者_如何学运维Element('iframe');
     this.ifram.style.display = 'none';
     if(this.ifram.addEventListener) this.ifram.addEventListener('load',ajax.receive,false);
     else if(this.ifram.attachEvent) this.ifram.attachEvent('onload',ajax.receive);
     document.body.appendChild(this.ifram);
    }
    this.ifram.setAttribute('src',urlstring);
  },
  receive: function()
  {
     content = ajax.ifram.contentWindow.document.body.innerHTML;
     returnurl = ajax.ifram.src;
     alert('return url: '+returnurl);
  }
};

however returnurl always holds the original urlstring value even if the response is different.

cheers peter


returnurl = ajax.ifram.contentWindow.location.href does the trick :)

0

精彩评论

暂无评论...
验证码 换一张
取 消