Open Javascript links in new tab

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information:CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
soma
Posts: 33
Joined: Fri Aug 10, 2012 12:02 am

Open Javascript links in new tab

Post by soma » Fri Oct 12, 2012 8:00 pm

On a given page there is a table with many rows and in each row is a link. I need to go through each link and extract some data off the resulting page. I have a javascript file which iterates over the table clicking links 1 at a time and that works fine. The problem is I can't navigate away from the table of links as shown below in the BACK command solution

Attempted Solutions:
BACK command
1. Click a link in the table which navigates to a new page in the same tab
2. extract data off new page
3. use the iMacros command

Code: Select all

BACK
to go back the table of links. The problem with this approach is that the site I am scraping does not handle navigation well at all. When the script executes the BACK command, the site takes me back to a landing page rather than back one step to the table of links. I then need to call a routine which navigates through several other pages before I can get back to the table of links. This works but is much too slow to be a viable solution for my business application

Extract HREF and open page in a new tab
My normal solution in a situation like this is to simply extract the

Code: Select all

HREF
of the link, open a new tab, and call

Code: Select all

URL GOTO=<extracted HREF>
. However on this site the links are just javascript commands which call submit on some form. Therefore extract the HREF of the url does not help me here

Ideally I want to be able to specific that iMacros opens a new tab when calling a tag command on a link

Code: Select all

TAG POS=1 TYPE=A ATTR=TXT:<anchor identifier here>
User avatar
bobis
Posts: 364
Joined: Sat Sep 11, 2010 3:34 pm
Contact:

Re: Open Javascript links in new tab

Post by bobis » Sat Oct 13, 2012 2:47 pm

you can also just reload the page after performing all needed actions.
just save current url with !urlcurrent and load page after clicking in each link and performing scrape content
Get Best iMacros scripts at http://imacrosbot.com/
soma
Posts: 33
Joined: Fri Aug 10, 2012 12:02 am

Re: Open Javascript links in new tab

Post by soma » Sat Oct 13, 2012 7:18 pm

Thanks for the suggestion. Unfortunately on this site the url never changes. Instead they are doing tricky stuff behind the scenes to reload the page.

I took a look at what was happening via Fiddler, an HTTP request debugger. When you click on a link, some javascript code gets executed that submits a form. This form has about 20 different fields with unique id's that are different every time you visit a page. It looks like they are using Siebel Web Engine to generate the user interface if that relevant
go3don
Posts: 2
Joined: Mon Mar 26, 2018 10:01 am

Re: Open Javascript links in new tab

Post by go3don » Mon Mar 26, 2018 10:14 am

To open new tab just use

Code: Select all

TAB T=2
iMacros GOTO supports javascript so you can generate new URL like this:

Code: Select all

VERSION BUILD=1001 RECORDER=CR
URL GOTO=https://url.com/file.php?id=61460
TAB T=2
URL GOTO=javascript:var<SP>url=new<SP>URL(window.location.href);var<SP>id=url.searchParams.get("id");window.location.href='https://url.com/post_new.php?issue_id='+id;
User avatar
thecoder2012
Posts: 333
Joined: Sat Aug 15, 2015 5:14 pm
Location: Internet
Contact:

Re: Open Javascript links in new tab

Post by thecoder2012 » Wed Apr 11, 2018 7:06 pm

No example html code or page url. Okay then is no full example possible. :wink:
go3don wrote:To open new tab just use

Code: Select all

TAB T=2
No. It's then only TAB 2 and not always a new tab.

Better is TAB OPEN:

Code: Select all

TAB OPEN
See http://wiki.imacros.net/TAB and open link in new tab javascript?

New page (TAB/Window) with JS and URL GOTO:

Code: Select all

URL GOTO=javascript:(function(){var<SP>link=document.createElement("a");link.id="someLink";link.href="http://www.google.de/";link.target="_blank";link.appendChild(document.createTextNode("test"));document.body.appendChild(link);document.getElementById("someLink").click();})();
New page without new TAB/Window with JS and URL GOTO like window.location.href (or replace):

Code: Select all

URL GOTO=javascript:(function(){var<SP>link=document.createElement("a");link.id="someLink";link.href="http://www.google.de/";link.appendChild(document.createTextNode("test"));document.body.appendChild(link);document.getElementById("someLink").click();})();
Join 9kw.eu Captcha Service now and let your iMacros continue downloads and scripts while you sleep. - Custom iMacros? Contact me! :idea:
Post Reply