passing in javascript values into iframe tag

后端 未结 3 1601
忘了有多久
忘了有多久 2021-02-09 12:48

What\'s the best way to pass in the value held in a javascript variable into an iframe call on the same html page? I\'m trying to improve my site\'s page response times by movin

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-09 13:43

    The only way you can pass values directly to an iframe of a page with a different domain is through the url, as querystring values, anchors, or perhaps some form of rewriting. Even if it's on the same domain, that's probably the easiest and safest way to pass it.

    Main document:

    document.getElementById('IframeID').src = "somepage.html?seed=" + custom_seed;
    

    Inner document:

    var seed = window.location.search.substring(window.location.search.indexOf('seed=') + 5);
    if (seed.indexOf('&') >= 0) {
        seed = seed.substring(0, seed.indexOf('&'));
    }
    

提交回复
热议问题