locked
open the anchor tag in new windodw in ajax jquery RRS feed

  • Question

  • User-1722422105 posted

    Hi all

    i want open the New Windodw In new tab.  when anchor tag is clicked here is Mycode

    <div class="modal fade" id="myfiles" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
    <div class="modal-content">
    <div class="modal-header">
    @*<button type="button" class="close" data-dissmiss="modal"><span aria-hidden="true">&times;</span></button>*@
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h4 class="modal-title" id="myModalLabel">Attach Document</h4>
    </div>
    <div class="modal-body">
    <form>
    <div class="form-group" id="frm1">
    <label for="Taxfiles">Tax files</label>
    <input type="text" class="form-control" id="lbl1" readonly="readonly" />

    <input type="file" class="form-control" id="FileUpload1" multiple placeholder="Tax Files" />


    <a id="mylink" class="alert-link" href="http://localhost:53173/Uploads/53/Uploaded.jpg" target="_blank" style="display:none;" onclick="func()" ; return false;">Open file</a>


    </div>


    </form>
    </div>


    <div class="modal-footer">
    <input type="button" id="btnUpload" value="Upload Files" />

    </div>
    </div>
    </div>
    </div>

    ///////////  code for open new window


    $(document).on('click', 'a', function (e) {
    e.preventDefault();
    var url = $(this).attr('href');
    window.open(url, '_blank');
    });

    it is working fine, but it apply in the all  anchor tag  in the page, but i want to apply only for

    <a id="mylink" class="alert-link" href="http://localhost:53173/Uploads/53/Uploaded.jpg" target="_blank" style="display:none;" onclick="func()" ; return false;">Open file</a> inside the div how we can access anchor tag

    Tuesday, July 3, 2018 12:49 AM

All replies

  • User-369506445 posted

    hi

    you can check it by ID below like :

     

    <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
    <script>
            $(document).on('click', 'a', function (e) {
                e.preventDefault();
               
                var id = $(this).attr("id");
                var url = $(this).attr('href');
    
                if (id == "myAsp") {
                    window.open(url, '_blank');
                } else {
                    window.open(url,'_self');
                }
                
            });
    </script>
    <a id="myAsp" href="http://asp.net">asp site</a>
    <a id="myGoogle" href="http://google.com">google site</a>
    <a id="myAspForum" href="https://forums.asp.net">asp Forum</a>

    Tuesday, July 3, 2018 4:48 AM
  • User1724605321 posted

    Hi sidu,

    Since you are already use onclick function in <a> tag , you can directly write the windows.open function in it :

     function func() {
             
                var url = $("#mylink").attr('href');
                window.open(url, '_blank');
            }

    Best Regards,

    Nan Yu

    Tuesday, July 3, 2018 6:07 AM
  • User-1716253493 posted

    Im not so familier, i think you can do like this

    $(document).on('click', 'a', function (e) {
    e.preventDefault();
    var url = $(this).attr('href');
    var tar = $(this).attr('target'); window.open(url, tar); });

    correct it if wrong

    Tuesday, July 3, 2018 7:27 AM