Apparently, this call to window.open is not valid under Internet Explorer. The Javascript code on my site is not running, I would assume it is due to that error.
The line it tells me the error is on, is the call to window.open, apparently an argument is not valid there.
$('.objeto').click(
function() {
var center = 'height=380,width=900,top='+((screen.width - 900)/2)+',left='+((screen.height - 380)/2);
var address = $(this).attr('id');
window.open (address,'Ver articulo', config=center);
}
);
The site runs fine under both Google Chrome, and Firefox.
In IE, you can't have spaces in your second variable (the new window's name).
Try:
window.open (address,'Ver_articulo', config=center);
Also worth re-iterating that IE9 (and possibly below) doesn't like hyphens ('-') in the window name (2nd parameter).
I know one of the comments mentioned this, but it's a bit buried - and it's one tip that just solved an issue for me.
I'm not sure what config is, you just need:
window.open (address,'VerArticulo', center);
Keep in mind though, it looks like your id attribute is invalid to get the effect here, you probably want to use something different, e.g. data-href="urlHere" on the element, if it's not an anchor already.
even thou it's kind a late with answer for OP, but for someone else stumbling across this post it might help:
Had exactly same problem as OP after trying to use "window.open" method. It turns out that Chrome is ok with original href tag with URL in it where IE seems to get confused with that. After removing href from link worked spot on.
CODE SAMPLE:
$(document).ready(function ()
{
$('a[rel^="external"]').each(function ()
{
var externalLink = $(this);
var externalLinkValue = externalLink.attr("href");
externalLink.unbind('click');
externalLink.removeAttr("href");
externalLink.click(function (event)
{
event.preventDefault();
followExtrenalLink = window.open(externalLinkValue,'_blank');
});
externalLink.hover(function ()
{
externalLink.css('cursor', 'pointer');
});
});
Related
I have a function written in javascript as follows,
<script>
function newPopup(url) {
popupWindow = window.open(url,'popUpWindow','height=700,width=1300,left=480,top=190,resizable=no,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes').focus();
}
</script>
And Its called like this within the href of a button
document.getElementById('user-help').href = 'Javascript:newPopup("<spring:message code="user.help.dashboard"></spring:message>")';
This works in Chrome and Opera. But doesn't work in IE and Firefox.In firefox just a blank page appears while in IE error called page cannot be displayed.
Can someone please give me a solution for this. I have searched, but did not find a favorable solution.
Try this,
<script>
function newPopup(url) {
var popupWindow = window.open(url,'popUpWindow','height=700,width=1300,left=480,top=190,resizable=no,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes');
popupWindow.focus();
}
</script>
And call like this,
document.getElementById('user-help').href = 'Javascript:newPopup("<spring:message code=\"user.help.dashboard\"></spring:message>")';
Hope it works for you, thank you.
I see several issues. First off, you have quoting issues in this:
"<spring:message code="user.help.dashboard"></spring:message>"
It isn't clear what you are trying to construct with that line, but that appears to be a syntax error to me.
Second off, you're trying to use that string as an URL for window.open(). That isn't a valid URL.
Third, you have a typo in your window.open() function call. There's an extraneous = sign in the calling args.
You have a typo in the window.open. There is an = sitting outside the spec parameter:
popupWindow = window.open(url,'popUpWindow',='height=700,
should be:
popupWindow = window.open(url,'popUpWindow','height=700,
I have a small piece of code for a template project I'm working on. There are three separate buttons, that point to three separate locations. In order to make it easier for content providers, I have these buttons calling minimal routines to load the next page.
The code is as follows:
/* navigation functions here for clarity and ease of editing if needed */
prevURL = 'ch0-2.html';
nextURL = 'ch2-1.html';
manURL = 'ch1-2.html';
function prevPage() {
window.location = prevURL;
}
function nextPage() {
window.location = nextURL;
}
function goManager() {
window.location = manURL;
}
This works perfectly in Firefox and Chrome, but seems to fail in Internet Explorer.
I open up the developer tools in IE (F12) and am presented with the message:
SCRIPT5009: 'manURL' is undefined
The location information (line 43, character 13) points to the "window.location = manURL" part of the code.
However, once the developer tools are open, if I hit F5 to reload the page, the button works without error until I close IE and reopen it, where it once again fails to respond and gives the same "undefined" error.
I'm baffled. Anyone have any ideas?
UPDATE
I know the variable declaration is poor, and that I can use window.location.href instead. What is relevant here is that the other two pieces of code, which are identical in all of these significant ways, work perfectly either way.
epascarello has put me on the right track. by removing all console.log commands, everything starts working. I'm just wondering why this happens, and would like to be able to give epascarello credit for helping me.
IE does not have console commands when the developer window is not open. So if you have them in there the code will not run. It will error out.
You can either comment out the lines or add in some code that adds what is missing.
if (typeof console === "undefined") {
console = {
log : function(){},
info : function(){},
error : function(){}
//add any others you are using
}
}
Try setting
window.location.href
instead of just window.location.
Source:
http://www.webdeveloper.com/forum/showthread.php?105181-Difference-between-window.location-and-window.location.href
Always define variables before using them ,being explicit (expressing the intention) is a good practice,
so define your variables like this,
var prevURL = 'http://google.com';
var nextURL = 'http://msn.com';
var manURL = 'http://stackoverflow.com';
You can try using
window.location.href
refer to this post for difference
Suggestion:
Make a jsfiddle.net for us so we could guide you easily
Trying to select the following link in html:
Nodequeue
with this Javascript:
jQuery("a:contains('Nodequeue')").trigger("click");
And I am receiving this error message:
Javascript console (:1): Unsafe JavaScript attempt to access frame with URL http://cdn.nprove.com/cpma/p/1/2/e/b/12ebf3bc368ry3ra.html?npuid=1310010225&rurl=&id=cpma-2n7eypbvio581300288437193&null=&r=366424962878227 from frame with URL http://www.benzinga.com/analyst-ratings/analyst-color/11/07/1742957/the-beef-stops-here. Domains, protocols and ports must match.
Any idea what might cause this?
I created a
JSFiddle of your code which you can look at and notice that in the console your error doesn't come up in Chrome 12 or FireFox 5. I'm not sure what version of jQuery you are using that is causing that or your DOM situation that may be triggering that error, however, try this potential fix:
(function(window, $) {
$.fn.triggerAnchor = function() {
return this.each(function(e) {
var href = $(this).attr('href');
window.location.href = href;
return false;
});
};
})(this, this.jQuery);
Then use with:
$("a:contains('Nodequeue')").triggerAnchor();
I don't think jQuery triggers anchors, and it certaintly doesn't trigger native click events. This is the closest thing I can think of to emulate that behavior.
You can see it 'working' here
Explanation of the code:
The code is simply a jQuery plugin that looks at the href attribute of anchor and sets the window location to that value. I wrote in the typical pattern of a wrapped closure to localize references to window and jQuery. I'm allowing you to call this on multiple anchors, but I'm assuming the average user would only need to run this once.
That error usually means you are making a javascript request from one frame to another. In this case, is the link in an iframe, or is jquery running in an iframe?
I have this script provided by #Felix Kling in this post HERE, but is crashing my IE when I use it; on FF 3.6, Opera, Chrome, Safari work fine.
Any idea why is this happening? A fix maybe?
var ajaxTimeout;
function autorun() {
if ($("#contactForm").is(":visible")){
if(ajaxTimeout) {
clearInterval(ajaxTimeout);
ajaxTimeout = false;
}
}
else if(!ajaxTimeout) {
ajaxTimeout = setInterval("refreshAjax();", 15000);
}
}
$(function autorun() {
setInterval("autorun();", 2000)
});
Thanks,
Cristian.
LE. Sorry, forgot to add details about that.
IE just closes, "encounter an error and needs to close, looking for a solution ...". IE 8.0 Windows7. If I load the page, I cannot open the debugger from the developer tools, but if I open the debugger before I load that page and press Start debug it doesn't show any errors or anything, but the page is not refreshing the grid as it was suppose to.
Here's what you're after:
$(function () {
var ajaxTimeout;
function autorun() {
if ($("#contactForm").is(":visible")){
if(ajaxTimeout) {
clearInterval(ajaxTimeout);
ajaxTimeout = false;
}
}
else if(!ajaxTimeout) {
ajaxTimeout = setInterval(refreshAjax, 15000);
}
}
setInterval(autorun, 2000);
});
IE doesn't at all like named functions used like this, and it's overriding the previously defined one. This is a long-standing bug not fixed until IE9. The core of the problem is that $(function autorun() { is taking over the autorun name, which is just queuing more and more runs of itself.
Also, it's better to pass function references to setInterval() directly, not strings.
I suspect that this is the culprit:
$(function autorun() {
setInterval("autorun();", 2000)
});
That's not really valid javascript. I think it's probably supposed to be something like:
$(document).ready(function() {
setInterval("autorun();", 2000);
});
[edit: there was an error in my suggestion above, and I have corrected it. I was incorrectly assigning the result of setInterval(...) to the variable ajaxTimeout. This ultimately caused the logic inside the main autorun() function to never initiate its interval on refreshAjax(), thus causing the code to appear to "do nothing".]
[edit: some have indicated that my suggestion was offered without enough explanation, so I'll try to provide that here.]
you were declaring function autorun() twice. Once at the top, and again in the bottom section where I've suggested that you should make changes. Both declarations are in the same scope, so the names will collide and behavior will be browser-dependent. Some browsers will let one function "hide" the other, while other browsers will (probably) refuse to compile it.
you have used a named function declaration (the second declaration of autorun) in an "inline" context. This may be allowed by some browsers (and some have suggested that it is actually valid by the standard -- though admittedly I thought it was not), but it will definitely cause problems in IE.
My suggestion changes the second declaration into an anonymous declaration so as to kill two birds with one stone: avoid a name collision, and use syntax that is supported across all browsers.
finally, I introduced the use of $(document).ready(...), because it's standard practice these days, when programming with jQuery. You can read more about it on jQuery's site. Long story short - it is directly equivalent to the $(function() {...}) syntax that you've used, so you can take it or leave it as you please.
I am using the prototype JavaScript library to read the contents of a text area (which is often the complete mark-up for another HTML page), create a new window and then set the new window content to be that same mark-up, like so:
var htmlContent = $("msHTML").value;
var win = window.open("preview.cfm", "Preview HTML", "left=20,top=20,width=500,height=500,toolbar=0,resizable=1,scrollbars=1");
win.document.write(htmlContent); //TODO - throwing an error in IE 7 - Error Invalid Argument
win.document.close();
This works just fine in Firefox but as mentioned in the comment, it's giving an Illegal Argument exception in IE7.
Can anyone help?
I couldn't find anything in the prototype library that might get around browser differences when setting document content. I know there might be another windowing library built on prototype that might work, but that seems like overkill for this issue I think.
Thanks in advance!
The 2nd parameter for
window.open(url, name, features);
"name" in IE, MUST NOT CONTAIN SPACES. (affects all versions of IE)
//works
window.open('page.html', 'mypage', '');
//FAILS in IE
window.open('page.html', 'my page', '');
Remove URL and Title from window.open() - it's a security related issue. You don't need to specify URL anyway since your overwriting window's content on the next line of your code.
This works:
var win = window.open('', '', 'left=20,top=20,' +
'width=500,height=500,toolbar=0,resizable=1,scrollbars=1');
win.document.write($("msHTML").value);