I have an iframe to preview some data.
The data is stored in a javascript variable :
var s = '<html><head></head><body><a href="#">Hello_world</a></body></html>';
I am passing the data [passing s] to the iframe SRC attribute via Javascript.
Here is the code :
document.getElementById('output_iframe1').src = "data:text/html;charset=utf-8," + escape(s);
So the data is loaded on the iframe except <a> elements.
The Problem is I can see text but not links. However, the element events are working fine(click,hover etc).
I inspected through Firebug and all are working well there.
I changed the HREF attribute to http://somesite/file.html on Firebug and amazingly it worked, but not with #.
Actually what i am doing wrong ??
Why i cant see LINKS without http:// ?
Thank you .
Update 1 : I tested it with latest Firefox 8.0 and it works well,also checked with Google Chrome [Works well,but clicking on any links disappearing all the links],Yeah as usual IE failed in all cases,it looks like IE doesn't know what is an Iframe
Use href=”javascript:void(0)” instead of href=”#”.
OR
Since you are assigning it to a src attribute, you need to encode the string before you apply it. This is because, usually src value is url and “#” is used in browsers url sometimes. Hope you understand what I am saying.
Use encodeURIComponent() or encodeURI(). See the syntax here
http://www.w3schools.com/jsref/jsref_encodeuricomponent.asp