Firefox & IE does not run innertext - javascript

I have a problem like this :
<div id='stickyid' style='display:block; color:red'>happi</div>
After write :
<script type="text/javascript">
var thevalue = document.getElementById("stickyid").innerText;
document.write(""+thevalue+"");
</script>
It runs ok on Chrome but not Firefox and IE. How can I fix it?

Try:
var thevalue = document.getElementById("stickyid").innerText || document.getElementById("stickyid").textContent;

demo: http://jsfiddle.net/E3ESv/
var thevalue = document.getElementById("stickyid").textContent;
Please visit 'innerText' works in IE, but not in Firefox for more help

Related

Javascript Snippet not working in Safari 11 & 12

does anyone know the reason why the following javascript snippet works in both Chrome & Firefox but not in the Safari 11 & 12 versions?
The only thing it does is take the value in the url parameter code and insert it in the url's on the page that need I want it to be in.
Are there any restrictions concerning javascript in the new Safari versions?
I can't find any info online..
<script>
window.addEventListener("DOMContentLoaded", function() {
if (window.location.href.indexOf('?code') > -1) {
var uniqueCode = window.location.search.split(/\?|&/g).filter(function(str){
return str.toLowerCase().indexOf('code') > -1
})[0].replace('code=','');
var codeLinks = document.querySelectorAll('[href*="/validate/promocode/"');
for (var i = 0; i < codeLinks.length; i++) {
var currentHref = codeLinks[i].href;
var newHref = currentHref.replace(/\/validate\/promocode\/.*\/buy\//, "/validate/promocode/" + uniqueCode + "/buy/");
codeLinks[i].href = newHref;
}
}
}, false);
</script>
I have no Mac to test this , but is it possible that Javascript is default disabled on version 11 and 12 on Mac?
Solved
The problem lies in the following line :
var codeLinks = document.querySelectorAll('[href*="/validate/promocode/"');
should be
var codeLinks = document.querySelectorAll('[href*="/validate/promocode/"]');
A small syntax error the other 4 browsers don't complain about.
Conclusion : Safari is much stricter on Syntaxerrors.

Popup blocker setting in IE 11 is not working

I am using below code to check popup blocker setting in IE 11. But regardless of any setting "Turn on Pop-Blocker" is checked on or checked off.
Internet Option=>Privacy=> "Turn on Pop-Blocker"
The window.open("/", "", "height=100,width=100"); is opening windows so my else part never get executed. I already spend 2 days but didn't found any solution yet. It seems IE is not working as expected. The same piece of code is working on Chrome, Firefox andenter code here safari perfectly fine.
<script >
var myQueryString = document.location.search;
function detectPopupBlocker()
{
var myTest = window.open("/", "", "height=100,width=100");
if (myTest=='false' || myTest == null || typeof(myTest )=='undefined')
{
window.location.href = '/ChromePopup.html';
myTest.close();
}
else
{
myTest.close();
}
}
"

Why is .innerText not working in Firefox? [duplicate]

This question already has answers here:
'innerText' works in IE, but not in Firefox
(15 answers)
Closed 7 years ago.
Here is my code
It's working perfect in all browsers but not in Firefox.
I tried many thing but didn't work at all.
Please can some one help me on this issue.
Am I doing something wrong.?
Is there any other way.?
I'M USING .innerText because values are coming from
<span class="jr-rating-wrapper-jr_stars-new-0">
4.5
</span>
There is no error on console.
<script type="text/javascript">
jQuery('#submitButton').click(function(){
var PostStartone = document.getElementById('jr-rating-wrapper-jr_stars-new-0').innerText;
var PostStarSec = document.getElementById('jr-rating-wrapper-jr_stars-new-1').innerText;
var PostStarThird = document.getElementById('jr-rating-wrapper-jr_stars-new-2').innerText;
var PostCapVal = document.getElementById('code').value;
var PostRBVal = "";
var selected = jQuery("div.jr_fieldDiv input[type='radio']:checked");
PostRBVal = selected.val();
jQuery.post("http://xyz/x/Update.php", {
GetStarOneValue : PostStartone ,
GetStarSecValue : PostStarSec ,
GetStarThirdValue : PostStarThird ,
GetCaptchValue : PostCapVal,
GetRadioBTNValue : PostRBVal});
});
</script>
innerText is the "old Internet Explorer" way of doing it.
Try textContent instead. Ideally you should use elem.textContent || elem.innerText, but if you're using jQuery you can just do jQuery("#the_id_here").text().

Javascript not working in FF or IE

I have some javascript code that gets the id of the element selected by the user, it works absolutely fine with Chrome, Safari, Opera but when it comes to Firefox and IE it doesn't seem to work at all.
It is located within a closure function and I have done some tests and found that it is this exact line that is breaking the code.
my function...
var myfunction = (function(){
var testId;
var item1;
var item2;
return{
animate: function(){
testId = window.event.target.id;
item1 = $('#heading' + testId);
item2 = $('#subheading' + testId);
//jquery operating on item1 and item2 goes here
}
};
}());
line that doesn't seem to be working...
testId = window.event.target.id;
Any help with this problem would be much appreciated.
Do this:
testId = (event.target || event.srcElement).id;
Hope it helps

jQuery Cleditor wysiwyg text editor: keyup() works in webkit browsers but not Firefox or IE

I'm trying to follow up on a previous Stackoverflow question about how to display content from a Cleditor textbox in an external HTML element such as a <p>. Here's the question and the fiddle which solves my problem in webkit browsers but not Firefox or IE:
Here's the code from the fiddle:
<textarea id="input" name="input"></textarea>
<p id="x"></p>
<script>
$("#input").cleditor();
$(".cleditorMain iframe").contents().find('body').bind('keyup',function(){
var v = $(this).text(); // or .html() if desired
$('#x').html(v);
});
</script>
I've read Get content of iframe from jquery that I need to use "window.top.... to access the main page and pass it that way because .contents() is not supported by all browsers" but i'm not sure how to use window.top for this purpose and am hoping someone might be able to shed some light on this topic.
The cleditor documentation states that it does have a "change" event which it claims to work with the 'keyup' event, but unfortunately in my testing it didn't work as expected with Firefox 7 (requires clicking out of the text-editor).
Jsfiddle: http://jsfiddle.net/qm4G6/27/
Code:
var cledit = $("#input").cleditor()[0];
cledit.change(function(){
var v = this.$area.context.value;
$('#x').html(v);
});
There is also another StackOverflow question which asked about the same thing, in which user Ling suggests modifying the plugin to add your own function:
Get content from jquery CLEditor
Edit:
Based on your comments with the above SO question result's not working, I've amended the code below.
This works in IE9 and IE9's "IE8" developer mode. http://jsfiddle.net/qm4G6/80/
$(document).ready(function(){
var cledit = $("#inputcledit").cleditor()[0];
$(cledit.$frame[0]).attr("id","cleditCool");
var cleditFrame;
if(!document.frames)
{
cleditFrame = $("#cleditCool")[0].contentWindow.document;
}
else
{
cleditFrame = document.frames["cleditCool"].document;
}
$( cleditFrame ).bind('keyup', function(){
var v = $(this).text();
$('#x').html(v);
});
});
Another Edit: To get the HTML, you have to find body within the iframe like $(this).find("body").html(). See the code below.
JSFiddle: http://jsfiddle.net/qm4G6/84/
var cledit = $("#inputcledit").cleditor()[0];
$(cledit.$frame[0]).attr("id","cleditCool");
var cleditFrame;
if(!document.frames)
{
cleditFrame = $("#cleditCool")[0].contentWindow.document;
}
else
{
cleditFrame = document.frames["cleditCool"].document;
}
$( cleditFrame ).bind('keyup', function(){
var v = $(this).find("body").html();
$('#x').html(v);
});
$("div.cleditorToolbar, .cleditorPopup div").bind("click",function(){
var v = $( cleditFrame ).find("body").html();
$('#x').html(v);
});
Since I answered the question that prompted you for this, I guess I'll answer this one too ;)
This works in Chrome and Firefox (I don't have access to IE):
$("#input").cleditor();
$( $(".cleditorMain iframe")[0].contentWindow.document ).bind('keyup', function(){
var v = $(this).text(); // or .html() if desired
$('#x').html(v);
});
Updated jsFiddle
UPDATE
This also works in Chrome and Firefox. Maybe IE too?
$("#input").cleditor();
$( $(".cleditorMain iframe")[0].contentDocument ).bind('keyup', function(){
var v = $(this).text(); // or .html() if desired
$('#x').html(v);
});
jsFiddle

Categories