This question already has answers here:
How to apply CSS to iframe?
(28 answers)
Closed 8 years ago.
I'm wanting to update an iframe with css in javascript. I know how to update the iframe body with the code below but is there a way to insert css into the head of the iframe?
Thanks David
var previewFrame = document.getElementById('previewFrame');
var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;
preview.open();
preview.write('New Content');
preview.close();
I think if you have iframe page under the same domain you should try this:
$("iframe").contents().find('head').append('<style type="text/css">' +'MY CSS IS HERE' + '</style>')
Related
This question already has answers here:
sup tag inside title tag html
(3 answers)
Closed 3 years ago.
This is my code:
<script>
document.title = unescape("My Text<sup>™</sup> For you");
</script>
Expected output: My Text ™ For you
Actual: My Text<sup>™</sup> For you
How do I fix this?
The page title doesn't accept HTML, you should be using the actual Trademark symbol ™
This question already has answers here:
How can I change div content with JavaScript?
(6 answers)
Closed 7 years ago.
How do i change the content of an div on an website that has an id with javascript?
<div class="chat-area" id="chat-area">[Changeable]</div>
I want to know how i add content where it says "[Changeable]" with javascript so i can run the command through the console.
I'd like if you keep your explainage simple, because im still very new to html/css/javascript ;)
In very simple JavaScript terms, you can use:
document.getElementById("chat-area").innerHTML = 'New Content';
And yes, this would work in GreaseMonkey / UserScripts too!
You can use the innerHTML property to achieve your goal like so:
document.getElementById("chat-area").innerHTML = "Your new content here";
This question already has answers here:
How can I access the contents of an iframe with JavaScript/jQuery?
(15 answers)
Closed 8 years ago.
I want get the attribute 'src' of a iframe from other html.
I can get the attribute of a iframe in the same html but not from other html,
look my code:
/////////iframe attribute from the same html//////////
var Mframe_src = $("#Mframe").attr('src');
alert(Mframe_src);
//////////iframe attribute from other html////////////
var frame_Ads = $("#Mframe").contents();
var Ads_src = frame_Ads.find("#ads");
alert(Ads_src.attr('src')); /// the alert present me undefined
That's impossible, you could try to get the iframe content by ajax though and then do something with that.
$.get("my iframe page").success(data){
//do something
});
This question already has answers here:
How do I check if an element is hidden in jQuery?
(65 answers)
Closed 8 years ago.
I want to get value of div attribute. Like I want to know whether the div is "display:block;" or "display:none" at the time of page load. If "display:block;" then it will be "display:block;" after the page load again if not then "display:none". Can anyone help me with jquery method or code?
Do this:
<script>
$(document).ready(function(){
var x =$("#divId").css("display");
alert(x);
});
</script>
This question already has answers here:
How to replace plain URLs with links?
(25 answers)
Closed 8 years ago.
Is there a way in pure Javascript to turn links in an HTML document into clickable links? I do not want to use regex to solve this problem.
Let's say I have this list in an HTML5 doc:
<pre>
http://www.test.com
http://www.example.com
http://nicelink.com
</pre>
And I want it to automatically turn into this when the page is loaded:
<pre>
http://www.test.com
http://www.example.com
http://nicelink.com
</pre>
What would the vanilla JS code look like if I put a script in the header? Something looping through the HTML code and replacing the lines I suppose but I cannot write it in JS.
Signy
A way to do this:
var str = $('pre').html().trim();
var ar = str.split('\n');
var html = "";
for(var i=0;i<ar.length;i++)
{
html +="<a href='"+ar[i]+"'>"+ar[i]+"</a><br>";
}
console.log(html);
$('body').html(html);
DEMO