0

I have the following html code.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function myTermsandConditions(){
            var myWindow = window.open("","MsgWindow","width=200,height=200");
            myWindow.document.write("<p>This is Terms and Conditions Window. Please go through all the Terms and Conditions for your references.</p>")
        }
    </script>
</head>
<body>
    <label class="sign_agree">
        <span id="signup-termservice" class="unchecked">    
        </span>I agree to the 
        <a href="" >Terms and Conditions</a> 
        .
    </label>     
    <button onclick="myTermsandConditions()">T&C</button>
</body>
</html>

Here I have a button for T&C and when I click on the button, a window will open and will show the custom message which is given using the function myTermsandConditions(). But I am trying to implement the same for Terms and Conditions link. And as per my requirement, I should not use the button but the window or the pop up should open when clicked on Terms and Conditions link which is given below by using the function myTermsandConditions().

<a href="" >Terms and Conditions</a>

I am trying to find the solution and learn in the process.

Mahi
  • 553
  • 2
  • 7
  • 23
  • 1
    i think you can add the onclick function to the href element – Jason Jul 05 '22 at 16:30
  • Does this answer your question? [How can I make a HTML a href hyperlink open a new window?](https://stackoverflow.com/questions/13335954/how-can-i-make-a-html-a-href-hyperlink-open-a-new-window) – Heretic Monkey Jul 05 '22 at 16:31
  • @HereticMonkey : I have checked the above link which you have shared, in that the external link is used for href or window.open(url,....) , but in my requirement, I need to use custom function contents to be shown when click on the Terms and Conditions link. – Mahi Jul 05 '22 at 16:37
  • And...? You can still use the part where it sets the the `onclick` to a function that calls `window.open()`, like your existing `myTermsandConditions`, right? It's bad form to have an anchor that depends on JavaScript for its contents anyway; good links work whether JavaScript is enabled or not. – Heretic Monkey Jul 05 '22 at 16:42
  • @HereticMonkey Yes I have used onclick to a function that calls window.open() and it worked. And when I open, the top of the window shows as about.blank . Is there any way to remove this site information (about.blank). Because i just wanted to show the content only. – Mahi Jul 05 '22 at 16:50
  • You can change it; set `document.title` of that window to what you want it to be (e.g., `""` to be blank). But you're working with 20-year-old technology here; most websites would use an HTML dialog for this purpose. – Heretic Monkey Jul 05 '22 at 18:48

1 Answers1

-1

You can add "onclick" on your tag too.

<a href="#" onclick="myTermsandConditions()">T&C</a>

vbotio
  • 1,566
  • 3
  • 26
  • 53