kurt.santo Posted July 9, 2007 Share Posted July 9, 2007 How do you accomodate for users, which have JavaScript disabled? Is there a standard code to could use?Cheers,Kurt Link to comment Share on other sites More sharing options...
jesh Posted July 9, 2007 Share Posted July 9, 2007 I think it depends on what you are trying to accomplish with the javascript. For example, if you want a link to open in a popup window, you can accommodate folks without javascript by doing something like this: <a href="somepage.html" onclick="window.open(this.href); return false;">Some Page</a> If javascript is enabled, the onclick code will function and the "return false" will stop the href from being followed. If, on the other hand, javascript is disabled, the link will take the user to the href value. Link to comment Share on other sites More sharing options...
kurt.santo Posted July 9, 2007 Author Share Posted July 9, 2007 I think it depends on what you are trying to accomplish with the javascript. For example, if you want a link to open in a popup window, you can accommodate folks without javascript by doing something like this:<a href="somepage.html" onclick="window.open(this.href); return false;">Some Page</a> If javascript is enabled, the onclick code will function and the "return false" will stop the href from being followed. If, on the other hand, javascript is disabled, the link will take the user to the href value. Had a go, but IE still opens the information bar (or whatever it is called at the top). The code I use to open a pop-up is as follows:<A href="flowers/crocus.htm" target="_blank" onClick="return popup(this, 'crocus', 458, 719); return false;"><IMG src="flowers/thumbnails/crocus.jpg" alt="Painting: Crocus" width="78" height="120" ></A>Where is my mistake?Kurt Link to comment Share on other sites More sharing options...
jesh Posted July 9, 2007 Share Posted July 9, 2007 Are you looking at the file locally in IE? IE has that security setting that will always show that information bar popup if you attempt to load a page locally that executes script. Either set yourself up a local webserver and load the page with http://localhost/mypage.html rather than something like file:///c:\myfiles\mypage.html, upload your page to an external webserver, or download and use a different browser like Firefox or Opera. Link to comment Share on other sites More sharing options...
kurt.santo Posted July 10, 2007 Author Share Posted July 10, 2007 Are you looking at the file locally in IE? IE has that security setting that will always show that information bar popup if you attempt to load a page locally that executes script. Either set yourself up a local webserver and load the page with http://localhost/mypage.html rather than something like file:///c:\myfiles\mypage.html, upload your page to an external webserver, or download and use a different browser like Firefox or Opera.Cheers Jesh, I am such a fool... Have a different problem now: When the IE security settings are set to the highest level the close button will not work. Is there a way to display it only to users with JavaScript enabled? Is kind of uncool to have a button, which does not work. And how would I simulate a user, who does have JavaScript disabled? Kind of unticked all boxes there are for Scripting in IE's security settings, but pop-up still opens normally.Kurt Link to comment Share on other sites More sharing options...
jesh Posted July 10, 2007 Share Posted July 10, 2007 I'm not aware of any way to determine which level of security a browser is set at. So, if a browser is set up to allow javascript but ignore window.close() calls, I don't believe there is too much you can do about it.As for only showing a button if javascript is enabled, you might try this:If CSS is enabled: <button style="display: none;" id="theButton" onclick="alert('you clicked it');">Click Me</button><script type="text/javascript">document.getElementById("theButton").style.display = "block";</script> Or, the pure javascript way: <script type="text/javascript">var button = document.createElement("button");button.id = "theButton";button.onclick = function() { alert('you clicked it'); }button.innerHTML = "Click Me";document.body.appendChild(button);</script> As for simulating a user who has javascript disabled, I would recommend downloading Firefox and using that as your main browser. You can download and install an extension to Firefox, called Web Developer Tools, that makes it very easy to enable/disable cookies, javascript, css, and images as well as do various other things that are useful when you build a webpage. Link to comment Share on other sites More sharing options...
justsomeguy Posted July 10, 2007 Share Posted July 10, 2007 I just want to point out that users who have Javascript disabled are different from users who have a high security setting in IE. Raising the IE security level does not disable Javascript, it just filters what Javascript is allowed to do. If a user has Javascript disabled altogether, they won't run any Javascript code at all.Also, the Opera browser makes it easy to switch things like this as well. When you hit the F12 button it pops up a menu like this: Link to comment Share on other sites More sharing options...
kurt.santo Posted July 14, 2007 Author Share Posted July 14, 2007 I'm not aware of any way to determine which level of security a browser is set at. So, if a browser is set up to allow javascript but ignore window.close() calls, I don't believe there is too much you can do about it.As for only showing a button if javascript is enabled, you might try this:If CSS is enabled:<button style="display: none;" id="theButton" onclick="alert('you clicked it');">Click Me</button><script type="text/javascript">document.getElementById("theButton").style.display = "block";</script> Or, the pure javascript way: <script type="text/javascript">var button = document.createElement("button");button.id = "theButton";button.onclick = function() { alert('you clicked it'); }button.innerHTML = "Click Me";document.body.appendChild(button);</script> As for simulating a user who has javascript disabled, I would recommend downloading Firefox and using that as your main browser. You can download and install an extension to Firefox, called Web Developer Tools, that makes it very easy to enable/disable cookies, javascript, css, and images as well as do various other things that are useful when you build a webpage. Would I put either of those two in the <head> section and insert a button with the "theButton" id? Tried both, but showed only the button without closing it.Cheers,Kurt Link to comment Share on other sites More sharing options...
jhecht Posted July 19, 2007 Share Posted July 19, 2007 generally the <noscript> tag is used. If javascript or whatever else is enabled, then the contents of in the <noscript> tag are not shown, otherwise it is presented like a normal HTML Element. Link to comment Share on other sites More sharing options...
kurt.santo Posted July 19, 2007 Author Share Posted July 19, 2007 generally the <noscript> tag is used. If javascript or whatever else is enabled, then the contents of in the <noscript> tag are not shown, otherwise it is presented like a normal HTML Element.I use the following code (kind of think now that might be the wrong way of doing it):<FORM action=""><INPUT type=button value="Close Window" onClick="java script:window.close();"></FORM>Where would I place the <noscript> tag?Cheers,Kurt Link to comment Share on other sites More sharing options...
boen_robot Posted July 19, 2007 Share Posted July 19, 2007 Where would I place the <noscript> tag?Almost anywhere in the body. The contents will appear at that spot. Link to comment Share on other sites More sharing options...
kurt.santo Posted July 21, 2007 Author Share Posted July 21, 2007 Almost anywhere in the body. The contents will appear at that spot.Cheers:-) But there is no way just to display a javascript generated "close window" button when javascript is enabled... (asked this in a different thread). What a shame...Thanks for you help,Kurt Link to comment Share on other sites More sharing options...
Synook Posted July 22, 2007 Share Posted July 22, 2007 Cheers:-) But there is no way just to display a javascript generated "close window" button when javascript is enabled... (asked this in a different thread). What a shame...What do you mean? You could just have <script type="text/javascript"> document.write("<input type=\"button\" onclick=\"window.close()\" value=\"Close Window\" />");</script> at where you want the button, and when the code executes it will place a button that closes the window at the point where the script is... unless you wanted something else Link to comment Share on other sites More sharing options...
kurt.santo Posted July 22, 2007 Author Share Posted July 22, 2007 What do you mean? You could just have <script type="text/javascript"> document.write("<input type=\"button\" onclick=\"window.close()\" value=\"Close Window\" />");</script> at where you want the button, and when the code executes it will place a button that closes the window at the point where the script is... unless you wanted something else That is what I am after, but unfortunately it does not work. It only shows the button. You cannot close the window. Used the following code (as given):<TD><script type="text/javascript"> document.write("<input type=\"button\" onclick=\"window.close()\" value=\"Close Window\" />");</script></TD>Do i have to place a window.close() function in head (tried in IE and FF without the file, which will later on open the popup)?Kurt Link to comment Share on other sites More sharing options...
Synook Posted July 23, 2007 Share Posted July 23, 2007 Umm... for security reasons, the window.close() function can only be executed on windows that have been opened by javascript. So, it will not close a window such as what you are viewing this forum in.However, try it on a window that was opened by javascript, and it should work :)You don't have to put the window.close() function in the header (I think). Link to comment Share on other sites More sharing options...
kurt.santo Posted July 23, 2007 Author Share Posted July 23, 2007 Umm... for security reasons, the window.close() function can only be executed on windows that have been opened by javascript. So, it will not close a window such as what you are viewing this forum in.However, try it on a window that was opened by javascript, and it should work :)You don't have to put the window.close() function in the header (I think).Great stuff!!! This works perfectly well...Just one final question: Could you achieve a similar thing with a plain "window close text" (without the use of a button)?Kurt Link to comment Share on other sites More sharing options...
aspnetguy Posted July 23, 2007 Share Posted July 23, 2007 document.write("<a href=\"java script:void(0)\" onclick=\"window.close()\">Close Window</a>"); Link to comment Share on other sites More sharing options...
kurt.santo Posted July 24, 2007 Author Share Posted July 24, 2007 document.write("<a href=\"java script:void(0)\" onclick=\"window.close()\">Close Window</a>"); Cheers, that is great:-)Kurt Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.