Well I’m having a hard time figuring this out, the deal it’s that I’m using this code in some tabs that I have, it works perfect in all browser except for Internet Explorer 10, 9, the tabs are showing but when you click on them the information doesn’t change. So after looking what the error it’s I have found that in IE one if it’s not running, here’s the code:
<script type="text/javascript">
Varien.Tabs = Class.create();
Varien.Tabs.prototype = {
initialize: function(selector) {
var self = this;
$$(selector+' a').each(this.initTab.bind(this));
},
initTab: function(el) {
el.href = 'javascript:void(0)';
if ($(el.parentNode).hasClassName('active')) {
this.showContent(el);
}
el.observe('click', this.showContent.bind(this, el));
},
showContent: function(a) {
var li = $(a.parentNode), ul = $(li.parentNode);
ul.select('li', 'ol').each(function(el){
var contents = $(el.id+'_contents');
//the problem lies here, in IE the if doesn't run
if (el == li) {
el.addClassName('active');
contents.show();
} else {
el.removeClassName('active');
contents.hide();
}
});
}
}
new Varien.Tabs('.product-tabs');
</script>
So the deal it’s that the condition of the IF statement it’s not running and I have no clue of why.
I'm using IE 10 and 9 since IE 8 it's working fine, also I'm not getting any errors in the console of IE .
Open the F12 tools and use the debugger. Set a break point on the line. See what li and el are and see if they are actually equal. I would probably try to compare the id or some other value that is unique to the li you are trying to match. you have to remember you are comparing two instances of jQuery the way your are doing it right now. To actually compare the node (element) you would do it this way: li[0] === el[0];
Try the debugger and use the watch window to see what the values actually are and try to compare the actual node, not jQuery instances.
If Your code is working fine with IE8 then try following code:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8">
This will make your code IE 8 compatible no matter which version of IE you are using.
The only thing you should take care is, your code should work fine in IE 8.
Well I have figured out what happen
ul.select('li', 'ol').each(function(el){
so in this line i had 'li' and 'ol', since the page didn't have any 'ol' the page in IE wasn0t working so since I remove
Related
I am learning chrome extension programming from the tutorial here .
You can find the full code for the chrome extension here.
The code snippet where I tried to remove few links:
var clean_twitter = function(){
var ugly = [];
ugly.push('.Trends module trends');
ugly.push('.flex-module');
ugly.push('.MomentMakerHomeModule-header');
ugly.push('.Footer module roaming-module');
ugly.push('.flex-module-header');
$('.promoted-tweet').hide(); // oops! :P
for(var i=0;i<ugly.length;i++) {
var u = $(ugly[i]).find('a'); // also 'b'
u.text('');
}
}
The code tries to remove some buttons and div from the twitter website.
Now, when I put it on my pc nothing happens. I tried to remove the change link inside the trends box and it isn't removed.
Please help if I am doing something wrong here. Thanks.
At the beginning of the process_new_tweets function there's a comment explaining how the presence or absence of .mini-profile in the DOM is used as a flag.
In summary, the absence of the .mini-profile element in the DOM means that the function returns and won't proceed any further. Since the tutorial was written it would appear that Twitter no longer has a .mini-profile element anywhere in its DOM, so the function is always returning and script execution is not proceeding any further.
Remove the following lines from the beginning of the process_new_tweets function:
var mp = document.getElementsByClassName('mini-profile');
if(mp.length === 0) { return; }
And the elements that you've selected in your clean_twitter function will be removed from the DOM as expected.
I have a form. It contains some hyperlinks. I can click on them and get another page in browsers like Google Chrome and Mozila Firefox but instead, I am unable to open them in IE9, IE10,..
What might be the problem? and whats the solution? help me.
In dev-tool(console), I am getting
un-terminated string constant error
.
Apart from any coding this could be the reason:
A previously installed browser or add-in might be interfering with ie browser on your computer.
or it might be a result of bad DCOM.
If bad DCOM is the problem you can get solution here:- http://www.techsupportall.com/links-are-not-working/
Jay,
This might happen due to incorrect concatenations or omission of the semicolon(;) at the end of statement.
Or may be any server variable that is not being populated. Like:
var var1 ='<% = someServerVariable %>'
someCode
It is possible that some someServerVariable is not being populated and the browser compiler would read the code as
var1 = someCode
Please look into your code and find out if there is any similar issue with your code. Or the best is to share your code snippet to point out the exact issue.
I ran into this same exact problem. For me, whenever I was embedding links in an ul / li list format, it just wouldn't let me click the first link (happens a lot navigation menus).It would only let me click the embedded ones. My work around for this was using java-script to create a force the click and pass.
Put this script in your head
<script>
function fakeClick(event, anchorObj) {
if (anchorObj.click) {
anchorObj.click()
} else if(document.createEvent) {
if(event.target !== anchorObj) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
var allowDefault = anchorObj.dispatchEvent(evt);
// you can check allowDefault for false to see if
// any handler called evt.preventDefault().
// Firefox will *not* redirect to anchorObj.href
// for you. However every other browser will.
}
}
}
</script>
And then in the body you can use this convention for any link you need to be forced clicked.
<a id="link" href="#YourDestinationLinkHere" onclick="fakeClick((event.target || event.srcElement).innerHTML)">Destination</a>
I've looked through quite a few answers and other places online, but I haven't found anyone that is experiencing the error in the same way that I am.
My browser just updated to IE10 and that brought this to our attention. If I run in compatibility mode, the function seems to work just fine. If I'm not in compatibility mode, I get an IE debugger error SCRIPT5002 - Function Expected error.
I've marked the place where I get the error with ==>. If I take that variable out and replace the variable with the document.frames... it then references that line as the problem. Any help would be appreciated.
I inherited this code from a previous employee and have only been working with javascript for about 3 months. Here is the code:
function FncSaveClient(){
//Submit Primary Client form
//Verify Data
==> var CntSumFrm = document.frames('IFrameSummary').document.all.item('DefaultFrm');
if (CntSumFrm.fireEvent('onsubmit') == true){
CntSumFrm.submit();
}
//If Edit Mode Submit Subforms
var IntAcctNum = CntSumFrm.TxtAcctNum.value
if (IntAcctNum != 0){
//Locations Subform
var CntLocFrm = document.frames('IFrameLocations').document.all.item('DefaultFrm');
if (CntLocFrm.fireEvent('onsubmit') == true){
CntLocFrm.submit();
}
//Contacts Subform
var CntContactTbl = document.frames('IFrameContacts').document.all.item('TblContactSummary')
if (CntContactTbl.rows.length-3 == 0){
alert('You must have at least one contact per client.');
document.all.item('BtnSubTblClientContacts').style.color='red';
}
//Classification Subform
var CntClassFrm = document.frames('IFrameMarketing').document.frames('IFrameClassification').document.all.item('DefaultFrm');
if (CntClassFrm.fireEvent('onsubmit') == true){
CntClassFrm.submit();
}
//Save Client Admin
var CntAdminFrm = document.frames('IFrameAdmin').document.all.item('DefaultFrm');
if (CntAdminFrm.fireEvent('onsubmit') == true){
CntAdminFrm.submit();
}
else
{
document.all.item('BtnSubTblSalesRel').style.color='red';
}
}
if(CntSumFrm.TxtDeleted.value == 1)
{
window.parent.location.href = '/Accounts/';
}
}
That code is full of ancient IE-specific code, that is probably not allowed anymore even by IE, unless in compatibility mode. You should look into replacing stuff like:
document.frames
document.all
.items()
I believe the error happens because frames or item (maybe both) is not a function when IE follows the JS standards.
I had a similar issue with a Java Script I wrote back in 2005 today. An external user using IE10, which we are still back in IE8, couldn't get things to work properly. It appears that document.all has been deprecated and is only accessibly in compatibility mode. I removed the check I had for IE and so it now uses document.getElementById which I already had for other browsers, and it appears to work even with compatibility mode turned off.
Here is a link to my page: http://myweb.students.wwu.edu/~tuckerb2/cs202/peanuts/project/open.html. I'm having trouble with all browsers, though it works in Firefox and Chrome, but not IE. I need to fix this parsing error that shows up in Firefox and IE so that it will a) not show an error in Fox and b) actually work in IE. Please help! Thank you!
There are a couple of things going on that you should have a look at
Firsly, in IE (6,7,8) window.innerHeight doesn't exist, instead you could use the below which will:
var h = (document.documentElement.clientHeight/2)-17;
The other issue is that once the letters match up in the center of the screen you do not stop the timers you have started. This means they will keep running and generate errors as the variables topLetters and bottomLetters are now larger than the size of the arrays topPos and bottomPos.
The function setInterval returns a reference to its timer, so you could then use the following code
var topTimer, bottomTimer;
function startSnowing() {
topTimer = setInterval("topFall()",10);
bottomTimer = setInterval("bottomRise()",10);
}
and change your topFall() and bottomRise() methods to something like
function bottomRise() {
if (bottomLetters < bottomPos.length) {
document.getElementById("bottomLetters").style.bottom = bottomPos[bottomLetters] + "px";
bottomLetters++;
}
else {
clearInterval(bottomTimer);
}
}
Hope this helps!
I have a function that shows a menu when clicking on it, and I want it to disappear after 5 seconds. This is my javascript - it works properly on desktop browser but it doesn't disappear on the mobile ones.
$(function() {
$('#prod_btn').click(function() {
$(this).addClass('selected').next('ul').css('display', 'block');
setTimeout(hideMenu, 5000);
});
});
function hideMenu() {
$('#prod_btn').removeClass('selected').next('ul').css('display', 'none');
}
Where is the problem?
Thanks
I've just had the same problem. My code is running great in any browser on my Mac, but on iOs devices it doesn't work.
I use ".bind(this)" on my timeout function and that is what is causing the problem for me.
When I extend the function object with ".bind" in my script it works like a charm.
My code is something like this:
searchTimeout = setTimeout(function() {
...
}.bind(this),250);
For this to work on iOs devices I (like mentioned above) just added this:
Function.prototype.bind = function(parent) {
var f = this;
var args = [];
for (var a = 1; a < arguments.length; a++) {
args[args.length] = arguments[a];
}
var temp = function() {
return f.apply(parent, args);
}
return(temp);
}
I don't see any .bind on your setTimeout, but for others with the same problem this may be the issue. That's why I'm posting :-)
I moved your example to a jsbin, and it's working on my iphone 4.
Please test it out going here from your devices: http://jsbin.com/asihac/5
You can see the code here http://jsbin.com/asihac/5/edit
The example is using jQuery - latest and I only added the required css class.
this doesn't apply to your code, but a common problem with long-running scripts failing on iOS devices is that MobileSafari kills a javascript thread after 10 seconds have elapsed. you should be able to use setTimeout and/or setInterval to work around this, or you can avoid it by making a shortcut to it and thereby running it as an app. see https://discussions.apple.com/thread/2298038, particularly the comments by Dane Harrigan.
Keep in mind also that any setTimeout function is actually likely fire while DOM elements are rendering if the delay is set to a value too short. While that might seem obvious, it can be easily confused with no method firing whatsoever. A good way to test is to have an alert prompt run.
window.onLoad(alert("hey!"));
Then check to see if your function fires after.