Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create IFrame programmatically and return its location.search

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
}
like image 315
JsRico Avatar asked Feb 25 '23 17:02

JsRico


1 Answers

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.)

like image 101
wong2 Avatar answered Mar 20 '23 17:03

wong2