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,
Related
I am creating a Chrome extension and I can't make call the function to work on the newly opened window.
I cant call alertit().
window.onload = function() {
var buttonn = document.getElementById("startt")
buttonn.addEventListener("click", openerr)
}
function openerr() {
var newwin = window.open(" https://www.instagram.com/explore/people/?hl=fr");
alertit();
};
function alertit() {
alert("wiiii")
}
Edit: Thanks Ivar for editing the question
Your grammar and description is pretty poor, so I'll try and get what you are intending.
So, you are opening a window with your chrome extension, and want to alert on it. This can't be done to my knowledge by calling window.open then directly something else, as they are two seperate things.
To control the new page, I suggest you use a content script: https://developer.chrome.com/extensions/content_scripts#registration
Best of luck
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
I am using a function in two sites but when I want to implement it to third site it does not work. When I look into firebug console it says its not a function. My function is in a separate file called profilter.js look like this:
jQuery.fn.sfProductFilter = function (options) {
options = options || {};
return this.each(function () {
var pf = new SFProductFilter(this, options)
})
}
and I am calling it from a page and code is:
$(document).ready(function(){
console.log($("ul.productSmall"));
$('ul.productSmall').sfProductFilter(); //says not a function.
});
I have checked through console.log followings
1- jQuery is included already
2- If I console.log from the js file it works but inside any code block it does not
3- ul.productSmall shows right results in console.log
I can provide link of site but just not providing it so moderator wont thinks its a spam.
I have struggled a lot please let me know where I am making mistake?
(Copied from comment above.)
You are including jQuery twice, the second load happens far below the inclusion of profilter.js and destroys your custom function.
Are you including the jquery ui script? Looks like .button() is called in
function myChecks(){
$("#checkboxcontainer input[type='checkbox']").button();
}
I have a hunch this will do the trick.
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');
});
});
I'm getting a JS error on displaying a page: Nothing concrete is specified but the line where it seems to be thrown. When looking into the source code of the page, I see the error is thrown inside the following script, but I can't understand why! It's only about loading images!
<SCRIPT language=JavaScript>
<!--
function newImage(arg) {
var rslt = new Image();
rslt.src = arg;
return rslt;
}
function changeImages(a, b) {
a.src = b;
}
newImage("\/_layouts\/images\/icon1.gif");
newImage("\/_layouts\/images\/icon2.gif");
// -->
</SCRIPT>
The error I am getting is when clicking on a drop down context menu on a page, for this line:
newImage("\/_layouts\/images\/icon1.gif");
The object doesn't accept this property or method
Code: 0
I really don't see what could happen... Any tips on what may be happening here?
Have you tried loading your scripts into a JS debugger such as Aptana or Firefox plugin like Firebug?
Why are you escaping the forward slashes. That's not necessary. The two lines should be:
newImage("/_layouts/images/icon1.gif");
newImage("/_layouts/images/icon2.gif");
It is hard to answer your question with the limited information provided:
You are not showing the complete script
You never said what the exact error message is, or even what browser is giving the error.
Which line number is the error supposedly coming from?
I'd recommend using Firebug in firefox for debugging javascript if you aren't already. IE tends to give bogus line numbers.
And as others have already said, the language attribute for script tags is deprecated.
Write proper xml with the " around attributes.
<script type="text/javascript">
function newImage(arg) {
var rslt = new Image();
rslt.src = arg;
return rslt;
}
function changeImages(a, b) {
a.src = b;
}
newImage("/_layouts/images/icon1.gif");
newImage("/_layouts/images/icon2.gif");
</script>
should your script block not be:
<script type="text/javascript">
?
For starters, start your script block with
<script type="text/javascript">
Not
<script language=JavaScript>
That's probably not the root of your problem, but since we can't see your script, that's about all we can offer.
You probably need to enlist the help of a Javascript debugger. I've never figured out how to make the various debuggers for IE work, so I can't help you if you're using IE.
If you're using Firefox or you CAN use Firefox, make sure you have a Tools / Javascript Debugger command. (If you don't, reinstall it and be sure to enable that option.) Next, open up the debugger, rerun the problem page, and see what comes up.
How are you calling changeImages? It looks as though you are not saving a reference to the images returned by newImage. You probably want to save the results of newImage and pass that to the changeImages routine. Then changeImages should look like this:
function changeImages(a, b) {
a.src = b.src;
}
You also may want to ensure that the images have finished loading before calling changeImages.
You've posted the routine that throws the error, without posting the error or showing us how you are calling it. If none of the answers posted fix your problem then please post some detail about how you are calling the method, which specific line the error is on, and what the error message is.
You firebug to debug.
http://www.mozilla.com/en-US/products/download.html?product=firefox-3.0.10&os=win&lang=en-US
https://addons.mozilla.org/en-US/firefox/addon/1843
JSLint is also a nice resource.
http://www.jslint.com/
Using CDATA instead of the <!-- // -->
http://www.w3schools.com/XML/xml_cdata.asp
<script type="text/javascript">
<![CDATA[
]]>
</script>