I need a function that takes a URL and appends an iframe 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 need a function that takes a URL and appends an iframe 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
}
Share
Improve this question
edited Mar 26, 2011 at 6:24
Justin Johnson
31.3k7 gold badges66 silver badges89 bronze badges
asked Mar 26, 2011 at 5:30
JsRicoJsRico
1132 silver badges5 bronze badges
1
- I can't make sense of that first sentence sorry. – alex Commented Mar 26, 2011 at 5:44
1 Answer
Reset to default 9I 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.");
but Chrome said that you can't access a frame with a different domain.(Domains, protocols and ports must match.)