Tested in FF 3.6 and Chrome (might need some tweaking for IE)
The Function: (Please see right hand pane before copying my code - thank you! >>>)
/*loads a url in the specified frame/iframe or returns the loaded url if url arg is blank
frame //DOM reference to a frame/iframe or string ID of an iframe in this document
url //url to href to. ignore or set=0 to return current url of page
*/
function framehref(frame,url){
if(typeof(frame)=='string'){//find iframe (will not find a frame):
frame=document.getElementById(frame);
}
if(frame.tagName=='IFRAME'){//iframe:
if(url==undefined){ return( frame.contentWindow.document.location );}
frame.contentWindow.document.location.href=url;
}else{//frame:
if(url==undefined){ return( frame.document.location );}
frame.document.location.href=url;
}
}
//sample usage:
alert(framehref('myIframe')); //alerts the current location of the iframe
framehref('myIframe',"http://www.google.com/"); //sends the iframe to google homepage
framehref(top.right,"http://www.google.com/"); //sends the right hand frame (in a frameset) to google homepage
6 comments:
frame.contentWindow.document.location.href=url;
This wouldn't work if the iframe contents aren't within the same domain with the parent page...
Correct: all cross-domain actions in javascript are blocked by the browser for security reasons.
coach outlet
michael kors outlet
nfl jerseys wholesale
christian louboutin outlet
coach outlet online
canada goose outlet
canada goose outlet store
canada goose outlet
christian louboutin sale
pandora outlet
shenyuhang20180608
ugg outlet
nike outlet
michael kors
jordan shoes
air jordan
lee jeans
nfl jerseys
cheap nfl jerseys
nike free
jordan 12
201811.9chenjinyan
광양출장샵
광양출장샵
상주출장샵
진안출장샵
상주출장샵
전북출장샵
전북출장샵
Great readingg this
Post a Comment