简体   繁体   中英

jQuery Attribute Usage for Target

Can anyone see why the following code is not causing my url top open up in a new window, ie:

        $(location).attr({
            href: toLoad,
            target: "_blank"
        });

where toLoad is my url.

Looking at the view source, all seems fine and basically looks like:

<a target="_blank" title="" href="http://......etc">ccc</a>

Any ideas what I could be doing wrong?

Thanks.

The jQuery wrapper is used for DOM elements, not arbitrary objects, and location ( window.location ) doesn't even have a target attribute. Simply do a window.open(...) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM