Jump to content

Better way to write this line of code?


Chrisj

Recommended Posts

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.

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.