views:

30

answers:

3

The problem is I'm using an iframe to process a login form via POST over https, but the parent hosting the iframe is http (although in the same domain)

is this doable?

I can't test this quite yet because I can only use https in our staging environment.

Thanks

  function process_form(f){


    var l = $("iframe#loginFrame");    
    if(l.length==0){      
      f.attr("target","loginFrame");      
      $('<iframe src="/player.htm?ajax=1"'+(!_DBG?' class="hide"':'')+' id="loginFrame" name="loginFrame"></iframe>').prependTo('body');      
      $("iframe#loginFrame").load(function() {
        var u = this.contentWindow.location;


        if(String(u).indexOf("confirm")>=0){ 
          change_form(1);
        }else if(u!=this.src){
          change_form(0);
        }
        log(u);
        log(this.src);

      });



    }else{
      warn("Frame already exists!"); 
    }

    change_form(-1);
    setTimeout(function(){ f.submit();},500);
    log(f);
  }
+1  A: 

Is document.getElementById('iframename').src what you're looking for?

EDIT

It appears that this has been previously answered. Try document.getElementById("iframename").documentWindow.location.href.

Jon
no, .src only returns the initial, i need the current one.
codeninja
i tried that. I get an documentWindow not defined error =/ (prefer with jquery)
codeninja
best answer but this method didnt work for https
codeninja
Okay, sorry to hear that
Jon
+1  A: 

Short answer, yes. To access the location of an iframe, btw, use myIframe.contentWindow.location. See http://www-archive.mozilla.org/docs/dom/domref/dom_frame_ref16.html for details.

Two frames in different protocols (http vs https) are in different origins, so you can't do anything that requires same-origin privileges.

From http://en.wikipedia.org/wiki/Same_origin_policy#Origin_determination_rules

The term "origin" is defined using the domain name, application layer protocol, and (in most browsers) TCP port of the HTML document running the script.

But the location should be accessible regardless of same-origin policy.

Mike Samuel
ok, so how to access it? lol... jquery is nice
codeninja
this worked. thank u... BUT does this work with https?
codeninja
yes. It works regardless of the protocol of the accessing origin or the iframe.
Mike Samuel
in my test of this, I was not able to retrieve the URL of the iframe when it was https from the parent http
codeninja
+1  A: 

you might be able to in your child frame call the parent so when the child frame loads you could do

domReady{ parent.form.hiddenField.value = document.location.href }

basically you pass from child back to parent. You'll have to experiment if the child can call a method in the parent which you might be able to do and pass the location to that method

dstarh
interesting idea.
codeninja