I know there are a lot of discussions about opening http pages in new windows and tabs,
but that's not what i'm looking for.
How do I open an empty new tab and run some arbitrary js in it?
That is when someone clicks my bookmarklet, a new tab should appear and code such as "document.write(foo)" should run in it with foo coming from the js on the tab where bookmarklet was clicked on.
This bookmarklet is the translation of your question:
javascript:void(function(foo){
var d=window.open("");
d.document.open();
d.document.write(foo);
d.document.close();
})("Foo")
Related
I am running a task in Chrome with Selenium in C#. The first/main tab stays open throughout this task. I then open a new tab. Do some stuff. Then close that tab. This might repeat 15-20 times per execution of the task.
I tried several options, for opening a new tab, including SendKeys and other "solutions" found on here, but injecting the below JavaScript into the webdriver is the only one that actually works for me.
var d=document,a=d.createElement('a');a.target='_blank';a.href='';a.innerHTML='.';d.body.appendChild(a);return a;
The problem is, that every time I open a new tab, the first/main tab scrolls to the bottom, then the new tab is opened. The web page in the first/main tab loads more stuff every time it scrolls to the bottom. This is problematic for several reasons which aren't relevant to the question.
My question is, why does this JS code scroll to the bottom of the first/main tab, and how do I stop it?
Directly click on the 'a' tag using javascript and do not return a .
var d=document,a=d.createElement('a');a.target='_blank';a.href='';a.innerHTML='.';d.body.appendChild(a);a.click();
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("var d=document,a=d.createElement('a');a.target='_blank';a.href='';a.innerHTML='.';d.body.appendChild(a);a.click();");
I have put google add sense code in my html page. But every time this link open in same tab. I want to open in new tab. I have googled for this and found following link.
https://support.google.com/adsense/answer/1354740?hl=en.
They are saying that they are not allow to open in new tab.But I have seen some sites like flipkart, amazon, w3school site in these site google add sence open in new tab. So the my question is there any way any one know please let us known.
add attrubute target "_blank" to your tag
some text
I making this bot in JavaScript in the chrome console. And one of the lines in my script is window.open('thewebsite','_self') so it opens a different website in the same window. However I cant seem to execute code on that new website that I opened with window.open(). For example I want to do document.getElementById().click() however its not clicking on the new website I made.
For example:
If I was on google.com the script would open googleimages. But I want the next line of code for example typing in the search bar to happen on google images.
window.open refreshes console, so you can't execute any code after.
You could try to get target url content and replace first page content, but you'll be blocked with Access-Control-Allow-Origin
What you're trying to achieve is indeed a macro. You should take a look at iMacros and see how they chain instructions from page to page.
I have a website that that suddenly start triggering a new ad window, something that I didn't do myself. I want to know how can I know which part of the page or script is responsible for opening the new window after I click a specific link?
There are a lot of files, so I am searching for a tool that can catch those specific javascript codes that do pop ups. Then I can find the source of the code and neutralize it. I prefer not to do manual search because there are a lot of JS files.
In IE press f12 and start the profiler. It will tell you what javascript has executed so far during your browsing session. I would look at the calls there to narrow it down.
It should be something like
window.open()
In JavaScript
I've just created a simple bookmarklet to load a URL containing a generated string. Is it possible to make this bookmarklet work like a normal bookmark:
When left-clicking opens in the current tab.
When middle-clicking opens in a new tab.
After putting in a folder, when selecting Open All in Tabs opens in a new tab.
The first works, but the second does the same as the first, and the third results in just javascript:... in the location bar.
Edit: Could be related to this bug report reported nine years ago. Is there some way to work around it?
You should try putting your JavaScript code in a separate page saved on your computer somewhere, then bookmark that instead.