Hi Javascript gurus, I have this Javascript code which is working fine on Firefox , but it is not working on IE 7. Any ideas why?
Here is the code
function TestWindow()
{
SimpleWindow('Default.aspx', 'Simple Test', 200, 200, 'yes')
}
function SimpleWindow(mypage,myname,w,h,scroll)
{
var win= null;
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
settings='height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',toolbar=no,location=no,status=no,menubar=no,resizable=no,dependent=no'
win=window.open(mypage,myname,settings)
if(parseInt(navigator.appVersion) >= 4)
{
win.window.focus();
}
}
You may have realized that IE is giving the error "Invalid argument."
IE doesn't seem to like window names with spaces in them. Change 'Simple Test' to 'SimpleTest' etc.
For myname parameter use only a-zA-Z0-9 characters. IE doesn't like any other, especially whitespace characters.
Check popup blockers
Check for reserved words. Your parameter name "scroll" is probably messing up your code in IE.
Related
So I've got this code to open up a gallery window, passing which category and which number/item from that category to display. It's working fine in Firefox and Chrome, but IE 9 keeps breaking on the window.open line, what am I doing wrong?
function newWindow(cat,n) {
var newWindow = "display.php?cat=" + cat + "&n=" + n;
var windowOpen = window.open (newWindow, 'Portfolio Display', 'height=622,width=960,toolbar=0,menubar=0,scrollbars=0,resizable=0,location=0,directories=0,status=0');
windowOpen.focus();
};
The newWindow variable was so that I didn't have to have a long string of quotes in there (just making sure that wasn't the error.
Don't use a space in the second parameter. I swear I've had trouble with this in the past, and I just stick to alphanumeric characters (UPDATE: I forgot about "_" as well) for the window "name" (second parameter). If this doesn't fix the problem in IE, although it has for me (I forget what versions I tested on), you can look at:
ie8 var w= window.open() - "Message: Invalid argument."
Oops, it turns out the problem was where I had 'Portfolio Display' as the second bit in window.open. Removed that and left it as
...newWindow, '', 'height...
and it works like a jiffy.
I have a string such as "Value = $val$" and I want to replace $val$ with some value like "$0.00"
so final string can look like "Value = $0.00"
This works in firefox and IE 7 and IE 8 but does not work in IE 9 any idea why? and how I can resolve the issue?
Any value other than $0.00 (e.g.$5.00) works without any issue.
http://jsfiddle.net/jhdVV/5/
edit: updated link with a textbox and a button to test with diff values.
http://jsfiddle.net/jhdVV/10/
In IE 9 I am getting "Value =$val$.00"
Browser is in Standards mode.
Note:
I am working on legacy code so , ideally I would like to stay away from tempting jquery solutions.
Any reason you're not simply doing this?
function replaceValue(source, find, replacement) {
return source.replace(find, replacement);
}
The $0 in your replacement text is essentially an uninitialized variable, the behavior of which is undefined. So, escape the dollar sign:
$$0.00
I've seen some similar questions to mine here, but they don't really answer me...
So I'm doing this: (Inside the document ready function)
$("#dest").focusin(function() {
$("#dest").val($.trim($("#dest").val()));
});
The ideia is when the user focus on a input called #dest trim all the space characters on it (previously added using focusout for visual comfort).
Right now, nothing is happening. :(
Hope someone can help me a bit here.
Thanks!
Is this a computer related problem?
I've tested all the code provided by commenters and none works. I'm using Firefox and Safari under OSX (Snow Leopard) 10.6.8 and also Safari under 10.8.2 (Lion) and I got the same results... OSX problem? -- Everything is ok, check my last edit!
Final Edit and Solution thanks to Phil Klein
My problem was using incorrectly jQuery's trim() function... According to the trim() documentation it does the following:
The $.trim() function removes all newlines, spaces (including
non-breaking spaces), and tabs from the beginning and end of the
supplied string. If these whitespace characters occur in the middle of
the string, they are preserved.
Yesterday I didn't read the last part where it says from the beginning and end of the supplied string -- Sorry everyone. :(
Lucky and after the drawing above, #Phil Klein understood my mistake and helped me with a solution:
$(function() {
$("#dest").on("focus", function() {
var dest = $(this);
dest.val(dest.val().split(" ").join(""));
});
});
You can read more about the solution and see an example here.
Thanks to #Phil Klein and also everyone who helped me on this one ;)
The example below removes all spaces from the contents of the textbox on focus. This particular example requires jQuery 1.7+ since it uses the new .on() API:
$(function() {
$("#dest").on("focus", function() {
var dest = $(this);
dest.val(dest.val().split(" ").join(""));
});
});
See this example: http://jsfiddle.net/RnZ5Y/5/
Try these : $.trim($("#dest").val());
correct me if i am wrong !!
try $("#dest").val().trim();,it worked for me.
If you're code above is executing before the page isn't fully ready then it's very likely that the #dest isn't found by jquery and the code for listening to the event doesn't get executed.
This function is working fine for your scenario. As it is taking only one space between character and not allow more than 2 space
$(function() {
$("#dest").on("focusout", function() {
var dest = $(this);
dest.val(jQuery.trim(dest.val()));
dest.val(dest.val().replace(/[ ]{2,}/, ' '));
});
});
I made my own function :)
look here please :)
function KillSpaces(phrase) {
var totalPhrase = "";
for (i = 0; i < phrase.length; i++)
{
if (phrase[i] != " ")
{
totalPhrase += phrase[i];
}
}
return totalPhrase;
}
you can easily use it when ever you want to!
$(document).ready(function(){
var test="for testing purposes only";
alert(killSpaces(test));
});
While debugging some jQuery that is not working in IE, I found this error message:
var item = $("#item_"+ itemArray[itemIndex]).find('a').text().trim();
Object doesn't support this property or method (script.js, line 100, character 2)
The character 2 doesn't make sense to me. Based on the text displayed character 2 would be the letter a in var but of course that doesn't make any sense.
(Should I not use var?)
I know that jQuery is working to some extent or the script would not have been able to get this far on my page.
IE doesn't have String.trim(), you'll need $.trim() (which uses native trim if available, emulates it in IE), like this:
var item = $.trim($("#item_"+ itemArray[itemIndex]).find('a').text());
IE doesn't have a trim method.
Instead, you can call jQuery.trim(...).
I would like to change a line of my javascript code based on whether the browser is IE7 or not. Here is the code for any other browser:
function showHint(myId)
{
document.getElementById(myId).style.display = "inline-block";
}
For IE7, I want display = "inline".
I've made an attempt at conditional compilation (this showed me how to detect the browser), but it didn't work:
function showHint(myId)
{
document.getElementById(myId).style.display = "inline-block";
/*#cc_on
#if(navigator.appVersion.indexOf(“MSIE 7.”)!=-1)
{
document.getElementById(myId).style.display = "inline";
}
#*/
}
Any help is greatly appreciated!
EDIT: I'm not using JQuery.
Set a global determined by the behavior of IE's conditional comment parsing:
<!--[if IE 7]><script> var isIE7 = true; </script><![endif]-->
You need to check navigator.userAgent.
If you use jQuery, you can simply write
if ($.browser.msie && $.browser.version === 7)
I think you can use regular expression to determine MSIE 7:
if(/MSIE 7/.test(navigator.appVersion)) { /* msie7 related code */ }
There is a Jquery Plugin detecting the Browser Version. I do not know the exact Link ...
Conditional compilation should work. It seems that your error is that you are using fancy quotes to delimit a string (“MSIE 7.”) or that you are attempting to assign display to something unknown to IE and it is having a fit over it and throwing an error. Here is a more concise version of the function that doesn't repeat itself and solves this issue:
function showHint(myId)
{
document.getElementById(myId).style.display = "inline" //#cc_on;
+ "-block";
}