I need a function that takes a URL and appends an ifr开发者_如何学Goame at that URL to the iframe's parent document body. The function should then return the window.location.search of that iframe, without knowing the URL argument that the function was given.
How can I do this in JavaScript?
EDIT: If the first sentence doesn't make sense to you, try this: I need a function that appends an iframe to the document body, given a URL as an argument. In other words:
function appendIFrame(url) {
// create iframe whose address is `url`
// append iframe to body of document
// return location.search of iframe's `window`, without using `url` argument
}
I tried this one:
function foo(url) {
var iframe = document.createElement("iframe");
iframe.src = url;
iframe.name = "frame"
document.body.appendChild(iframe);
return frames["frame"].location.host;
}
foo("http://google.com");
but Chrome said that you can't access a frame with a different domain.(Domains, protocols and ports must match.)
精彩评论