最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Create IFrame programmatically and return its location.search - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 9

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

but Chrome said that you can't access a frame with a different domain.(Domains, protocols and ports must match.)

发布评论

评论列表(0)

  1. 暂无评论