2

I want to make a footer credit protection using javascript. I've seen one using jquery. But it didn't worked properly. I want to apply that code to my blogger templates. I've written the following javascript code.

<!DOCTYPE html>
<html>
    <head>

        <script type="text/javascript">

            function lol(){

                var footer = document.getElementById("mycreditlink");

                    if (footer.hasAttribute("href")) {
                    footer.setAttribute("href", "http://grplusbd.net");
                    }

                    if (footer == null){
                    window.location.href = "http://grplusbd.net";
                    }
            }   

            window.onload = function(){lol();};

        </script>
    </head>
    <body>
        <div>
            Powered By <a href='http://google.com' id='#mycreditlink'>My Site</a>
        </div>
    </body>
</html>

But it isn't working properly either. I want it to make the footer url change automatically and if the id="mycreditlink" is removed by the client, it will redirect automatically to my website home. I need help immediately. If the code works, I will enode it and add to my templates.

1
  • 1
    What do you mean by "But isn't working properly either"? What exactly is the problem you are facing? Commented Jun 7, 2016 at 7:33

2 Answers 2

2
<div>
    Powered By <a href='http://google.com' id='mycreditlink'>My Site</a>
</div>

There is a error here: id='#mycreditlink' need to be like: id='mycreditlink'

And

function lol(){

                var footer = document.getElementById("mycreditlink");

                    if (footer.hasAttribute("href")) {
                    footer.setAttribute("href", "http://grplusbd.net");
                    }

                    if (footer == null){
                    window.location.href = "http://grplusbd.net";
                    }
            }   

window.onload=function(){lol();};

or

window.onload=lol();
Sign up to request clarification or add additional context in comments.

1 Comment

footer.setAttribute is working fine. But if the id='mycreditlink' removed, the page isn't redirecting.
0

You can make use of jQuery as I have done below...

<script type="text/javascript">

        function lol(){

            var footer = jQuery("#mycreditlink");

                if (footer) {
                    jQuery(footer).attr("href", "http://grplusbd.net");
                }

                else {
                window.location = "http://grplusbd.net";
                }
        }   

        window.onload = function(){lol();};

</script>

4 Comments

OP doesnt want window.location in else condition. According to the post if the element itself is not present then only he wants to redirect
Yes, when the user removes the element jQuery(footer).attr("href") will become NULL and will automatically enter the else part
Check this code. Element is present(withour href attrbute) but your code is going into else condition. So ideally you should check for element itself for redirection and not href attribute. He wants to redirect only if element with id mycreditlink is not present.
Ok, then I have edited my code if that is the case, but it still remains unclear what does he want

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.