So I have what seems to be a simple problem. I'm trying to automatically open a specific link on a page using the following code:
// ==UserScript==
// @name AutoClicker
// @include https://example.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @grant GM_addStyle
// ==/UserScript==
var TargetLink = $("a:contains('cars')")
if (TargetLink.length)
window.location.href = TargetLink[0].href
//--- but open it in a new tab
Which works splendidly.
The only problem is that I don't know a way to open the selected link in a new tab. I've tried iterations of the following code, but to no avail:
var TargetLink = $("a:contains('cars,' '_blank')")
I know I'll need to use _blank
, but I'm not sure exactly where or whether I should write it in jQuery or not. I've also tried placing _blank outside of contains, but I'm not exactly sure how I'd write the code in jQuery.
I simply want the selected link to open in a new tab upon being clicked. Any suggestions or thoughts?