|
ufarn posted:Thanks. There's no risk of exposing passwords because the password checker runs locally. Nobody can intercept the password because it's not being sent anywhere.
|
# ? Apr 18, 2012 20:45 |
|
|
# ? May 16, 2024 17:17 |
|
I need to programmatically add a script element to an existing HTML page, from a JS function, likecode:
Also, I need to write some settings from a database to a config file readable by JS, and I'm dithering on the format to use for this. JSON's easier for the JS to read, XML's easier for the database to write. Question is, is it more painful for the database to write JSON than for JS to parse XML? Don't know if it's a relational database or a document one, and the config file only needs to be written when the database updates, so JSON seems the better option to me, but I want second opinions from folk that know better than me.
|
# ? Apr 20, 2012 21:47 |
|
darthbob88 posted:I need to programmatically add a script element to an existing HTML page Why? darthbob88 posted:
It's because document.write does not work properly after a page is finished loading.
|
# ? Apr 20, 2012 21:54 |
Is what I'm trying to do possible? I have a file hosted on a sharepoint server and want to read the contents remotely.code:
|
|
# ? Apr 20, 2012 22:07 |
|
Suspicious Dish posted:Why? Short answer: Work. Long answer: At the moment, installing my employer's web service consists of two parts at minimum. Include our files in the header, all 6 of them*, and make one call to our service at the bottom of the page. See here. Anything wrapped in 4-Tell comments or referencing 4TellBoost is my doing. My boss would like to reduce that to two lines, by including one file which imports all the other files and writes out the call to our service. Everything works in my test environment, I can do it just fine, I just want to know how far from best practices this sort of thing is and how likely I am to get tarred and feathered for my audacity. Now that I think of it, can possibly do something with $(document).ready(), will try that now. * To be fair, 2 of those files are 3rd party libraries and 2 are CSS files that can probably be merged safely, but still, that's more files than I'd like to use for our service. Edit: We're trying to make it easier to install this so our customers can install it themselves rather than having me do it. Same with the config file, if we can let the client modify their configuration using some dashboard service I don't have to do it and we can sign more clients more quickly. darthbob88 fucked around with this message at 22:56 on Apr 20, 2012 |
# ? Apr 20, 2012 22:43 |
|
darthbob88 posted:Short answer: Work. Right. The reason I asked "Why?" wasn't to berate you for doing something silly, but so we can determine the best solution for everybody. If you did this because you wanted to load code at runtime, I'd suggest require.js instead. If you just want one copy/paste line, then create a file called loader-async.js with: code:
code:
|
# ? Apr 20, 2012 22:58 |
|
If your goal is to have doStuff() executed in the present document, the direct way is to execute it. If you want to execute it and catch syntax errors, the direct way is to evaluate it. Adding a script element involves a lot of stuff that is not directely related to executing your code, and the security of the code is an issue either way. innerHTML should not be set to a string that might confuse an HTML parser. Create a text node for that.
|
# ? Apr 20, 2012 22:58 |
|
Suspicious Dish posted:Right. The reason I asked "Why?" wasn't to berate you for doing something silly, but so we can determine the best solution for everybody. If you did this because you wanted to load code at runtime, I'd suggest require.js instead. If you just want one copy/paste line, then create a file called loader-async.js with: That looks like about what I need. Actually, it looks like an elaborated version of my current method, so that should suit my needs just fine. Edit: Actually, it may make a difference but we want two lines; one that's just <script src="http://myfile.js"> and one that's <script>myfile.setClient("Lolbutts")</script>, where the setClient function is the one that writes everything out and imports everything, because just what files we import depends on the client. Gazpacho: I don't need to execute doStuff() now, I want to execute it later. Part of that function is a screen scraper, so we want to run doStuff as late as possible, possibly even when the document's finished loading. darthbob88 fucked around with this message at 23:29 on Apr 20, 2012 |
# ? Apr 20, 2012 23:20 |
|
darthbob88 posted:That looks like about what I need. Actually, it looks like an elaborated version of my current method, so that should suit my needs just fine. Right. You could use jQuery and $(document).ready, but I was thinking that maybe all your customers didn't have (or didn't want) jQuery on their pages.
|
# ? Apr 20, 2012 23:26 |
|
Suspicious Dish posted:Right. You could use jQuery and $(document).ready, but I was thinking that maybe all your customers didn't have (or didn't want) jQuery on their pages. Actually, considering that our service makes extensive use of jQuery, it's one of the first files that we include if the customer doesn't already have it. $(document).ready was actually my second thought on how to do this best. Following on from the edit I just made, setClient is ATM code:
code:
|
# ? Apr 20, 2012 23:45 |
|
Repeat after me:
I will not use document.write. I will not use document.write. You can find countless sources on the internet explaining why. If you require jQuery, then you can simplify the code to: code:
|
# ? Apr 21, 2012 00:13 |
|
Suspicious Dish posted:Repeat after me: That looks much better. Going to look into head.js and also require.js as long as I'm looking. Thanks for the help!
|
# ? Apr 21, 2012 00:28 |
|
Does opening a new window fire an event? Alternatively: do plugins open new windows through the browser's javascript interface? What I want to do: I want to write an Opera user javascript that fires before any new window (or tab) is opened, examine the to-be-opened window's address and possibly modify it before the window is actually opened. If it fires an event, I could probably use Opera's BeforeEvent listener. If plugins use window.open, I could probably use defineMagicFunction. If neither of those happen, I guess I'm SOL.
|
# ? May 6, 2012 18:52 |
|
What do you mean by "plugin"? Flash? Flash doesn't have the native capability to open a new window. Most Flash sites implement pop-ups by going to a link with the "_blank" target (how this works inside Flash internally, I don't know), or by calling out to JavaScript using an FSCommand, ExternalInterface, or going to a javascript: url.
|
# ? May 6, 2012 18:58 |
|
Suspicious Dish posted:What do you mean by "plugin"? Flash? Flash doesn't have the native capability to open a new window. Most Flash sites implement pop-ups by going to a link with the "_blank" target (how this works inside Flash internally, I don't know), or by calling out to JavaScript using an FSCommand, ExternalInterface, or going to a java script: url. That's exactly what I meant. I figured that plugins (including flash) can't actually just open new windows, they have to request the browser to open a new window somehow. I'm trying to intercept that "somehow". java script: urls should not be a problem, since user javascript has BeforeJavascriptURL handlers. I'll check out if the google knows anything about FSCommand or ExternalInterface.
|
# ? May 6, 2012 19:18 |
|
FSCommand and ExternalInterface are just two ways of calling JavaScript code (or another external service -- when you embed the ActiveX control, you can override these handlers yourself) from Flash. So if you can intercept JavaScript, you can do anything.
|
# ? May 6, 2012 19:42 |
|
edit nvm
hayden. fucked around with this message at 22:36 on May 6, 2012 |
# ? May 6, 2012 22:26 |
|
Yet another question - is there a recommended way of embedding JSON configuration data into a page? Right now I have a script tag with a src attribute as well as text content, where the content is the configuration data. The script pointed to by the src attribute parses the content and everything works, but I've read a couple blog posts suggesting that this is a bad idea/against the html5 spec/etc. I could always make another request to grab the configuration, but it seems like that should be avoidable.
|
# ? May 8, 2012 06:37 |
|
The strategy I usually see is something like:code:
|
# ? May 8, 2012 06:40 |
|
Okay so I've showed this to a few people and mostly got really confused looks. This is for a uni assessment and I still get pretty with a lot of basic stuff so I hope I'm not just missing something obvious. We're to make a website that sells mobile phones. And that's a part of the order form page. It's supposed to calculate and give me a total. But all it seems to do is reset the page or something when you click calculate and I'm trying to get the prices to pop up in the text boxes depending on what you select. code:
|
# ? May 23, 2012 11:02 |
|
Seedy Wizard posted:Okay so I've showed this to a few people and mostly got really confused looks. This is for a uni assessment and I still get pretty with a lot of basic stuff so I hope I'm not just missing something obvious. Using a development tool* to debug, it was pretty trivial to find two errors that happen in calculate(); purchase_form has no member called deliver this line: result=result.toFixed(2); result is undefined, so you cannot call result.toFixed() To stop the page from refreshing, return false at the end of calculate(); You probably also want to check that the your conversions form fields are valid numbers before doing calculations (function isNaN()). * Opera, Chrome, IE and Safari have built-in development tools, Firefox has Firebug extension.
|
# ? May 23, 2012 11:27 |
|
You also seem to be calling parseFloat twice on the values. Not sure if that matters or not but it's redundant. And definitely learn to use the debugger. That should be the first thing you go to when something doesn't work.
|
# ? May 23, 2012 12:19 |
|
Coding Javascript without a debugger like Firebug is like trying to have sex without touching anything. It doesn't feel good, nothing gets accomplished, and it just makes you feel stupid for trying.
|
# ? May 23, 2012 14:39 |
|
Seedy Wizard posted:Okay so I've showed this to a few people and mostly got really confused looks. This is for a uni assessment and I still get pretty with a lot of basic stuff so I hope I'm not just missing something obvious. It's refreshing because it's breaking. Also because you don't have return false at the end, but as it is it's not even making it to the end. I would make add an array with the values and loop through to calculate the total, then multiply everything by the quantity. Make sure to set the default quantity to 1 or it'll be NaN if nothing is entered. parseFloat twice is redundant.
|
# ? May 26, 2012 18:35 |
|
Thanks for the help guys. I just finished it up and got everything working now. I do remember them mentioning Firebug about a month ago, and using it really helped me to work out the kinks.
|
# ? May 28, 2012 02:16 |
|
Firebug is unfortunately dead. The debugger is buggy (oh ho ho) because the old JSD 1.0 API is unmaimtained, and JSD 2.0 isn't quite finished yet. Mozilla is building a new set of development tools in tandem with their work on their new JavaScript engine, and all that fancyness. It lost its lead maintainer, and the progress on "Firebug 2.0" is slow. In the latest Nightly builds of Firefox, they already have a JavaScript console and a web inspector. They aren't too useful, as there's no debugger yet, or really any basic functionality provided by Firebug. I highly recommend you check out the WebKit developer tools, available in Chrome/Safari/Midori/what have you.
|
# ? May 28, 2012 02:49 |
|
I you use jslint (you probably should) and Notepad++ (also pretty good), download the gently caress out of this plugin: http://sourceforge.net/projects/jslintnpp/ Ctrl+Shift+F5 lints your current file and moves the cursor to the first error. Makes linting soooo much quicker, holy poo poo. Polishing old and busted javascript became so much less of a chore.
|
# ? May 28, 2012 20:13 |
|
I must say that Opera has the prettiest debug console I've ever seen. P'raps not the most useful, though I may not have given it a fair shake, but it's definitely the prettiest. My question: Have run into issues with prototype.js and their interfering with proper JSON. Stack Overflow post on the subject, not mine For political reasons, we can't simply delete Array.prototype.toJSON, so I have to write a toJSON function for our system, and it's giving me trouble. What am I doing wrong, aside from writing my own toJSON function? JavaScript code:
Also, holy poo poo we have good code formatting now.
|
# ? May 28, 2012 20:28 |
|
I don't have any other advice other than "prototype.js dead, do not use it".
|
# ? May 28, 2012 21:52 |
|
Suspicious Dish posted:I don't have any other advice other than "prototype.js dead, do not use it". I don't want to use it, but the client does, and breaking client code is frowned upon, no matter how bad it may be and how many standards it may violate. I'm powerfully tempted to put a false function in to keep my boss happy and put "delete Array.prototype.toJSON;" somewhere useful. ETA: Considering that the other method I found to solve the prototype.js conflict has failed, I will do that. darthbob88 fucked around with this message at 00:27 on May 29, 2012 |
# ? May 28, 2012 22:12 |
|
So I'm trying to get an element to change styles when it is moved over like so:JavaScript code:
|
# ? May 30, 2012 04:08 |
|
tinaun posted:So I'm trying to get an element to change styles when it is moved over like so: Baaed on this code, I don't understand why the display function is getting called on page load. Is all of this wrapped in a load handler or something?
|
# ? May 30, 2012 04:14 |
|
tinaun posted:So I'm trying to get an element to change styles when it is moved over like so: When you say display(opt) you're literally asking to call display and pass in opt to it while evaluating the arguments to opt.addEventListener. Something like this might work better (if I remember what 'this' gets set to for event listeners correctly, which I might now): JavaScript code:
|
# ? May 30, 2012 04:18 |
|
code:
|
# ? May 30, 2012 04:29 |
|
OddObserver posted:
It wasn't working, but removing "event" from the function header made it work perfectly. Suspicious Dish posted:
|
# ? May 30, 2012 04:47 |
|
tinaun posted:I would do that but I have no access to the source itself. JavaScript code:
|
# ? May 30, 2012 05:08 |
|
Wheany posted:
Wait. You mean you can dynamically create CSS style elements? I'm going to abuse that so hard.
|
# ? May 30, 2012 08:51 |
|
darthbob88 posted:Wait. You mean you can dynamically create CSS style elements? I'm going to abuse that so hard. Dude, you can dynamically create image files that you then base64-encode and set as a data url to an img-tag. I've done it and it is horribawesome. All the images on that page are created on-the-fly with javascript. (I've done the same with pngs but don't have access to them right now) e: here it is Wheany fucked around with this message at 21:38 on May 30, 2012 |
# ? May 30, 2012 09:28 |
|
darthbob88 posted:Wait. You mean you can dynamically create CSS style elements? I'm going to abuse that so hard. You can actually mess with the styles themselves. From what I've messed with, it's pretty cross browser friendly too. There are some cases that need to be handled with IE, but it works. I wrote a stupid little jQuery plugin that swaps out stylesheets this way. You can also edit the styles themselves using javascript if you really want to. Here's a good place to start if this stuff sounds interesting for some reason.
|
# ? May 30, 2012 15:16 |
|
|
# ? May 16, 2024 17:17 |
|
Mogomra posted:You can actually mess with the styles themselves. From what I've messed with, it's pretty cross browser friendly too. There are some cases that need to be handled with IE, but it works. Wheany posted:Dude, you can dynamically create image files that you then base64-encode and set as a data url to an img-tag. I've done it and it is horribawesome. All the images on that page are created on-the-fly with javascript. How have I gone so long without knowing any of this was possible, I could do so many terrible things with all this. Most of them I can do now, but I can use this to make them wonderfully terrible. I'm not sure whether to thank you or curse you for giving me this knowledge.
|
# ? May 30, 2012 17:05 |