Control link clicks in JavaScript

As the straight left

In JavaScript, you can control clicking on links <a> by:

Obja.click (), where objA is a linked <a> object.

Example:

When making a website, for maintenance and simplicity, each page is linked with a <IFRAME> header file: header. HTML and a footer file: footer.html.

As you know, if you click on a link in <IFRAME> and the Target of the link is not _top or _parent or _blank, the new page will be opened only in the IFRAME.

Now, in the header page, header. HTML, there is a text box txtNewAddress, an image, imgButton, and I’m asked to click on the image to take the contents of the text box txtNewAddress to a new page, and the new page is to replace the entire page, that is, Cannot be displayed only in <IFRAME>.

To read the content of the text box, you have to use JavaScript of course. It’s natural to think:

<a href= “javascript:ReadTextBox()” target= “top” ><img SRC = “ok.gif” id= “imgButton” ></a>

The problem is that this will give you an error. Because clicking on the link opens a new page at the top level without the ReadTextBox() function.

The solution is to write:

< a href = “javascript: ReadTextBox ()” > < img SRC = “ok. ImgButton GIF” id = “” > < / a >

Add another link:

<a id=”aNewPage” target=”_top”></a>

After reading the contents of the text box from ReadTextBox(), modify the href of the link aNewPage and trigger its click.

    function UpToTaxi()

    {

        var url = “”;

       

        txt = document.getElementById(“txtNewAddress”);

        if( txt.value != “” )

        {

url += “? newurl=” + txt.value;

        }

       

        obj = document.getElementById(“aNewPage”);

        obj.href = “newpage.aspx” + url;

        obj.click();

    }