PDA

View Full Version : Modifying the contents of an iframe?


okendoze
03-03-2008, 04:18 AM
I want to display a web page through an iframe with modified CSS. For example, I'd have Google.com displayed through an iframe without the Google logo above the search box. How is it done?

Kor
03-03-2008, 09:13 AM
It is not done. For obvious security reasons there is no way to modify a document which belongs to another domain. Cross-domains changing is not allowed.

rnd me
03-03-2008, 06:58 PM
if you build your application as an external script file, you can inject that script file into the page when your browser is at google.com by using a bookmarklet.

javascript can add html, and modify css, so you use it to customize the page.

check out this article (http://slayeroffice.com/articles/favelet_article.html) for some helpful ideas.

so, while you can't really do it in an iframe, you can kinda do it using a bookmarklet.

okendoze
03-04-2008, 01:36 AM
Kor:

I was thinking more of modifying a web page on the client side so that it appears different by using Javascript to add/change CSS. I was hoping that I could have Javascript output the source of the webpage displayed through an iframe using DOM innerHTML or something similar, but I'm beginning to doubt that it's possible.

rnd me:

I'm pretty sure what you've given me is what I need but I having trouble understanding it. I'll look into it more. Thanks a bunch.

Update: Nope. I'm not understanding how I can use this.

nincha
03-05-2008, 12:27 AM
You can modify it using javascript, frameName.getElementById('google element').innerHTML = str;

okendoze
03-05-2008, 12:31 AM
I was thinking something of the sort, but I didn't try it. I'll check it out right now.

Update: Having trouble. I wrote two pages:

test_pg.htm

<html>
<head>
<script type="text/javascript">
function modify()
{
var x = frame1.getElementById('edit1').innerHTML;
document.write(x);
}
function modify2()
{
var x = document.getElementById("frame1").contentDocument;
document.write(x.getElementById("edit1").childNodes[0].nodeValue);
}
</script>
</head>
<body>

<iframe src="test_pg2.htm" id="frame1" name="frame1"></iframe>
<br /><br />
<input type="button" onclick="modify()" value="Test" />
<input type="button" onclick="modify2()" value="Test 2" />

</body>
</html>


test_pg2.htm

<html>
<head>
</head>
<body>

<div id="edit1">test</div>

</body>
</html>


Why won't modify() write the contents of edit1?
How can I get modify2() to write to the same page, not to a new one?

okendoze
03-06-2008, 04:37 AM
I just realized you responded to my threads at both forums, Kor. :thumbsup:

I found something that will work for me and it will not work if it involves different domains, which isn't the case, fortunately. I suppose I could still persue rnd_me's solution, but I'll stick with this one for the moment. Thanks to both of you.