jQuery change the SRC and ID of an iFrame

吃可爱长大的小学妹 提交于 2020-01-07 00:35:48

问题


On my blog, I'm using a script that reveals anonymous messages as their normal username instead of anonymous. The script works fine on pages that I can make, but on pages that are default generated by my host (such as /ask, containing a message box which I cannot edit), I can't edit the code for the ask box so therefore it won't work. If anyone could provide a jQuery code that will

  1. Change the iFrame SRC with an ID of #askbox from "http://www.tumblr.com/ask_form/jamescharless.com" to "http://jamescharless.com/askbox"
  2. Remove the ID from the iFrame so it simply doesn't have an id

If anyone could help me it would be EXTREMELY helpful.


回答1:


This should change your IFrame src

$("#askbox").attr("src", "http://jamescharless.com/askbox");

You could try:

$("#askbox").removeAttr("id");

Combine the two:

$("#askbox").attr("src", "http://jamescharless.com/askbox").removeAttr("id");

Trying to solve your scripting problem...

Opening the page in a debugger you can run:

document.getElementById('wrapper');

but not

document.getElementById('ask_form') - it throws an error

Plan B

How about injecting a fresh IFrame?

$('#ask_form').parent().html('<iframe width="100%" height="149" 
    src="http://jamescharless.com/askbox" frameBorder="0" 
    scrolling="no" style="overflow: hidden; background-color: transparent;">
    </iframe>');



回答2:


   $(document).ready(function(){
       $('#askbox').attr("src", "http://jamescharless.com/askbox");
       $('#askbox').removeAttr("id");
   });


来源:https://stackoverflow.com/questions/10627767/jquery-change-the-src-and-id-of-an-iframe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!