简体   繁体   中英

Extracting the url variable from an iFrame

I'm using the Bits-on-the-run API to upload videos using these instructions , the thing is I have to include the upload form into an iframe, the upload form will upload the video and after it finishes it will redirect to another page with the video id as a url variable.

What I'm trying to do is to get that url variable from the iframe when the upload finishes.

Here's the iframe example:

<iframe width="650" scrolling="auto" height="220" frameborder="0" src="http://developer.longtailvideo.com/botr/demo/upload/"></iframe>

when the uplaod finishes, the iframe redirects to:

<iframe width="650" scrolling="auto" height="220" frameborder="0" src="http://developer.longtailvideo.com/botr/demo/upload/show.php?video_key=xxxxx"></iframe>

Such that xxxxx is the video key I want to extract in the parent page, I'll use this video key in a hidden input in order to submit another form.

Is tehre a way I can get this url variable when the redirect happens?

Try this:

ifr=document.getElementById('Your_Iframe_Id');

ifr.contentWindow.onload=function (){
  ssearch=ifr.contentWindow.location.search; // = ?video_key=xxxxx
  /* do something with ssearch */
  return;
}

Timing is very important in this case because ifr.contentWindow does not exist before it is first loaded. I suggest, that you first load a page from your server to the IFRAME and then assign the onload -eventhandler from that page to the host page.

Or you can wait untill the whole host page is loaded ( window.onload ) and then assign the eventhandler for ifr.contentWindow .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM