开发者

get iframe redirection url in javascript

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜