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

jquery - change src of iframe with javascript on pageload - Stack Overflow

programmeradmin3浏览0评论

I have this in a javascript file to diguise the source as much as possible

$(document).ready(function () {
    document.getElementById('myframe1').src = ".html";

});

and in the html

<iframe id="myframe1" width="900" height="700" src=""></iframe>

Sorry I am a bit of a notice with javascript. Any help with be great! thanks.

I have this in a javascript file to diguise the source as much as possible

$(document).ready(function () {
    document.getElementById('myframe1').src = "http://www.mysite./index.html";

});

and in the html

<iframe id="myframe1" width="900" height="700" src=""></iframe>

Sorry I am a bit of a notice with javascript. Any help with be great! thanks.

Share Improve this question edited Oct 1, 2012 at 10:57 killerwhale asked Oct 1, 2012 at 10:42 killerwhalekillerwhale 231 silver badge3 bronze badges 2
  • 1 Are you using jQuery or plain javascript? Your code says one thing and your tagging say another. – Niklas Commented Oct 1, 2012 at 10:43
  • 1 tbh I didn't know. Glad there are both options here though. – killerwhale Commented Oct 1, 2012 at 11:23
Add a ment  | 

1 Answer 1

Reset to default 7

With jQuery:

<script type="text/javascript">
    $(document).ready(function () {
        $("#myFrame1").attr("src", "http://www.mysite./index.html");
    });
</script>

With plain javascript:

<script type="text/javascript">
    window.onload = init;

    function init() {
        document.getElementById('myframe1').src = "http://www.mysite./index.html";
    }
</script>

You can add the function to the onload event like above.

发布评论

评论列表(0)

  1. 暂无评论