I'm having problems with navitation on safari using nodejs with expressjs and javascript. I have links with a function on its onclick event like this one (simplified version):
<a href="#" onclick="goToPublicView('/home/main')">
I have this method defined on javascript (is important to know that this is a reduced example. Is necesary to have the onclick event with a function for doing more stuff rather than navigation):
function goToPublicView(viewUrl) {
window.location = window.location.origin + viewUrl;
}
When the link is clicked on chrome or firefox it works perfectly, but on safary this method doesn't seems to work (no error messages that I could see).
If I write the method on console it works
goToPublicView('/home/main');
I don't understand what could be the problem. Any idea?
it seems to be any problem with browser. I reinstalled safari and it works fine.
Related
I have a link:
someText
it works fine everywhere except ie(i try ie11) i have this error
This page can’t be displayed.
Make sure the web address //ieframe.dll/dnserror.htm# is correct.
How can i solve this?
If you use a javascript URI scheme in a HTML href attribute, this is different to using an onclick event handler.
In IE, the result of executing that JavaScript will replace the currently loaded document.
To avoid this (without refactoring your code to not do things this way), you can end your href with the javascript operator void, which tells your javascript to return nothing, at all (well, undefined).
Then IE will stay on the current page.
<a href="javascript:someObject.someFunction(); void 0" ...
...and you probably don't want the target="_blank" since you're telling a new window to run your JavaScript code, and your function is not available in that window.
I would do this instead:
someText
It will open a new tab as you intended, and it works in chrome, firefox and IE.
I have added a piece of javascript code and it is not getting reflected in some of my peer's machine. Don't know whats going wrong.
This is what I did.
OnClick of a button, there was an existing JS function and I added an overlay feature inside the click event like,
function existing() {
var testDate = document.getElementById('test');
......
.....
newOverlay(); // This is the newly added function
}
I defined the newOverlay() as
function newOverlay(){
document.getElementbyId('divId').style.display = 'block';
}
I have defined the new function above the existing() and both the functions are inside the head tag
When I check this change in my local environment, it was working fine and there was no issues. When I deployed to the server, it was working fine for me and my peer could not see the change in firefox. But, he can verify the change in IE and Chrome.
We were thinking of some cache in the browser and we cleared the cache (ctrl+shft+del --> Everything) and tried. The issues occurred again. The part I added was not in the DOM itself. We tried Ctrl+F5, but it was not helpful.
When we reset the firefox browser and tried, the change got reflected and it was working fine. Don't know what was exactly happening. The issue is still occurring in some of our machines. Kindly share your thoughts.
Note: The entire JavaScript is inside a JSP and all are using the same version of Firefox (latest)
Try double quoting in the getElementById(). "id_name" instead of 'id_name'. Sometimes browsers are prone to this kind of bugs.
I am having an odd problem in my onclick handler.
I am calling a javascript function "download" in the onclick of an . This has been in use on production websites for years. Recently, I get a strange javascript error when clicking the button in Firefox or Chrome (not a problem in IE8). Firefox says "TypeError: download is not a function" and Chrome says "TypeError: string is not a function".
HTML:
<a onclick="download('position','container','ids');return false;" href="#">Run download</a>
JS:
function download(position, container, ids) {
alert('in download');
}
You can see this demonstrated in this Fiddle.
Primarily, I would like to know WHY this doesn't work (other functions work fine). It looks like if I rename the function or use a button instead of a link, the problem will be solved as well, but deploying such a change will be a nightmare. If it is necessary, that's fine, but I want to know why the download function no longer works.
It seems that, with HTML5, <a> tags support a new attribute named "download" (see this link for example), that has an empty value by default.
Your code will work if you change it to:
<a onclick="self.download('position','container','ids');return false;" href="#">Run download</a>
Indeed, events (onclick in this case) run in the scope of the element they are bound to (<a> here), so "download" means this.download if it exists.
Why is this simple link example not working in Firefox? It is working in IE and Chrome.
js fiddle sample
I am using windows XP. My Firefox version is 16.0.
Your fiddle sample shouldn't work in any browser because you've defined the getItems() method inside the onload handler that is the jsfiddle default (as set on the left-hand side) which in turn means that it is not in scope from the inline onclick="getItems()" attribute.
It works in FF if you fix that by selecting no wrap (head) instead of onLoad, thus making your function global: http://jsfiddle.net/u6bKr/1/
(Note that this has nothing to do with href="javascript:void(0);")
My research for getItems() showed what in some situations this function is defined as native function. I don't know why. To avoid this trouble try to rename function getItems.
http://jsfiddle.net/u6bKr/3/
UPDATE:
As specified in comment by Boris Zbarsky this trouble can be also avoided when adding window. before getItems() (e.g. window.getItems()).
The document.ondrop seems to work in chrome, but not in firefox?
Attached is an example:
http://auth.letschat.info/test2.php
If you drop a file on to the page it should pop up an alert box. However it doesn't work in firefox, but does in chrome.
When I use firefox console the document.ondrop handler is correctly set.
Assuming the original javascript looks like this and works in Chrome:
document.ondrop=function(event){
alert("hello");
}
It can be changed to work in both Firefox and Chrome. Firefox requires you to stop the default action from occuring when you drag a file over, which can be solved by using the ondragover event. The following javascript code will also work in Firefox:
document.ondragover = function(event){
event.preventDefault();
}
document.ondrop=function(event){
alert("hello");
}
I found this solution by looking at w3schools and looking for the differences between their simple example and your code.
From html5rocks on slide #18 there is also an html5 example of another way to use drag and drop by adding the listener to the page.