Chrisj Posted October 22, 2014 Share Posted October 22, 2014 Can you suggest a better way to write this code (I didn't create it): <body onload="getParameterByName('url')"> <a href="" id="urllink" >Click Here</a> </body> so, I don't have to change the <body> tag? Quote Link to comment https://forums.phpfreaks.com/topic/291998-better-way-to-write-this-line-of-code/ Share on other sites More sharing options...
NotionCommotion Posted October 22, 2014 Share Posted October 22, 2014 Can you suggest a better way to write this code (I didn't create it): No, it is perfect as is assuming you want it to do exactly what it does. If you want it to do something different, please let us know what that is. Quote Link to comment https://forums.phpfreaks.com/topic/291998-better-way-to-write-this-line-of-code/#findComment-1494441 Share on other sites More sharing options...
ginerjm Posted October 23, 2014 Share Posted October 23, 2014 Pretty sketchy question here. What does the anchor tag do for you exactly? Not much as written. Is that your question? I mean - you posted 3 lines of code and asked about it but didn't state which line you wanted our opinion on. Really - try to be more specific next time. Quote Link to comment https://forums.phpfreaks.com/topic/291998-better-way-to-write-this-line-of-code/#findComment-1494444 Share on other sites More sharing options...
cyberRobot Posted October 23, 2014 Share Posted October 23, 2014 For what it's worth, some would suggest that you avoid inline JavaScript. The "onload" attribute, for example, could be replaced with JavaScript's window.onload event handler. More information can be found here: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onload For more information as to why you might want to switch, you could research "Unobtrusive JavaScript". The following article will get you started: http://en.wikipedia.org/wiki/Unobtrusive_JavaScript Quote Link to comment https://forums.phpfreaks.com/topic/291998-better-way-to-write-this-line-of-code/#findComment-1494460 Share on other sites More sharing options...
codefossa Posted October 23, 2014 Share Posted October 23, 2014 If you meant you wanted the javascript outside of the body tag, then maybe this would be what you wanted. Left the option for adding more JS after load rather than just one function called, but there's tons of ways to do that. <head> <script type="text/javascript"> // Wait for load window.addEventListener("load", function() { // Do whatever .. getParameterByName("url"); }, false); </script> </head> <body> <!-- Added "#" as target to avoid moving pages without JS --> <a href="#" id="urllink">Click Here</a> </body> Quote Link to comment https://forums.phpfreaks.com/topic/291998-better-way-to-write-this-line-of-code/#findComment-1494461 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.