Here's what I need to do. I'm using Google Chrome. I have page that auto-reloads every 5 seconds using a script:
javascript: timeout=prompt("Set timeout [s]");
current=location.href;
if(timeout>0)
setTimeout('reload()',1000*timeout);
else
location.replace(current);
function reload()
{
setTimeout('reload()',1000*timeout);
fr4me='<frameset cols=\'*\'>\n<frame src=\''+current+'\'/>'; fr4me+='</frameset>';
with(document){write(fr4me);void(close())};
}
I found that script by Googling.
The reason why the page auto-reloads every 5 seconds is I'm waiting for a specific link or url to appear in the page. It appears at random times. Once I see the link I'm waiting for, I immediately click the link. That's fine.
But I want more. What I want is the page will auto-reload and I want it to auto-detect the the link I'm waiting for. Once the script finds the link I'm waiting for, it automatically loads that link on a new tab or page.
For example, I'm auto-reloading www.example.com. I'm waiting for a specific url "BUY NOW". When the page auto-reloads, it checks if there's a url "BUY NOW". If it sees one, it should automatically open that link.
Thanks.
For inspiration, check out what I have done it in my Chrome Extension "Auto-Reload". The code is here.
You should create yourself an extension (from what I understand of your question, that's what you are implying). Once the page reloads, you can use jQuery (for example) to scrap the page for your link.
Related
I'm trying to book a table at a restaurant. After I click on the book button, the page forwards, checks back to confirm availability with the server (over the course of maybe 2 seconds) and then opens a JavaScript confirmation pop-up in the browser.
Will I be fine with chooseOkOnNextConfirmation before I press the button and thus before the page forwards or should I add another (or move) chooseOkOnNextConfirmation after the click during the availability check?
Would it hurt to have several chooseOkOnNextConfirmation commands in a row? Would they interfere with each other?
It is essential that I get the timing right. Too early and the command might be executed on the wrong page, too late and the JavaScript pop-up stops my script. Please note that I can not test the script nor can I look at the page's JavaScript properties as bookings are closed right now and will only be available later.
Alternatively, should I use clickAndWait instead of click (the URL doesn't change though and the command may cause errors)? Can I use assertConfirmationPresent to determine whether the page is fully loaded before assertConfirmation or will it be too late since the pop-up already stopped my script?
What I have for now looks as follows:
chooseOkOnNextConfirmation
click //*[#id="table_id"]/thead/tr/th[1]/input
assertConfirmation glob:Are you sure you want to submit your request
for the following unit: Location Description:*
Btw, turns out globbing doesn't work for the command assertConfirmation. I get the error Confirmation message doesn't match actual message in the log unless the text in target matches the text in the pop-up exactly. Any ideas how to work around or how to make glob:* work?
I'm trying to write a script (bookmarklet, really) which has two parts. At the end of the first part, I want to click a button on the page which takes me to a second page. I then want the script to continue running after the second page has loaded. Is this possible?
Every web page load is treated separately by the browser, so there is no way to get a script to continue running where it started off. Here are a few solutions though:
1) Save state to cookies, then read the cookies from the script on the second page to pick up where you left off. For instance, you could save the user's name "John Doe" to a cookie in the first page, then the script in the second page could load the user's name from the cookie. This is probably what you'll want to end up doing.
2) Instead of loading a new page in the browser window, load your new page in an iFrame, and the script running in your outer window won't be interrupted. You can reach inside iFrames with JavaScript as long as they are on the same origin.
You aren't able to load a new page and continue a script from the previous page. But you could ajax load the new page, use the history API to modify the URL, and your script would keep running.
I want to know, if it is possible and how to run javascript code in console in new page, when somebody click on link in my page.
For example. I have got page and there is button. When somebody click on it, it will redirect to another page. In this page It will run my own javascript code, sended from previous page and appeared in console of new page.
This way I want to change for example stylesheet of some selected page and demonstrate the changes.
Thank you.
Shortest answer: No.
Short answer:
This would effectively violate the same-origin policy, and would be a nightmare as far as XSS is concerned.
Imagine for a moment that someone created an 'infected' link, when clicked would infect all the links on the next page in the same manner. Eventually when on the correct page, these infected links would run some code that would snatch up details of what was occurring inside the page (keystrokes, clicks, etc...) and send it back to a server.
All this without ever touching the user's machine.
The closest thing you can do is create a bookmarklet or userscript. It's up to the user to place these things on their computer, and run them on the correct page.
I want to calculate time consumed in redirecting from 1 webpage to another webpage.
For Example:
1) I am using Facebook in Google Chrome browser.
I have shared 1 link on my Facebook profile like below:
http://www.webdeveloper.com/
(It's not only Facebook. It can be any domain having link to another domain).
2) When I click on this link from my Facebook profile, then this website will open in new tab.
3) I want to calculate time difference in miliseconds or microseconds between below two events:
First Event: Time of clicking link "http://www.webdeveloper.com/" from my Facebook profile.
Second Event: Time of completely loading webpage of "http://www.webdeveloper.com/".
Thank you in advance.
Unless you load the linked page yourself into a frame or with xmlhhtp request, your facebook page does not have control of another page. In other words, as soon as the user clicks the link you have no control and it runs separately. If you use a frame or load the page ajax style with javascript into an object, it's not going to give you the same kind of timing. So this is basically a pointless excercise as you can't do it. You could potentially setup your own browser with whatever analyzer so it will give you timings but you can't set up any code that would time it for visitors, for the aforementioned reason. If it was possible to do such things then this code could also manipulate the linked to page and take over it. With such lax security you couldn't trust any link you click.
A website contains a "random" link, which loads a url that returns a 307 redirecting to the url we want. It works fine: click it and you load a random page. The problem is that each time you click it, the browser assumes you're loading the same page: so if you're on the homepage, then you follow the random link 5 times, then you press back, you'll be taken all the way back to the homepage, with no way to find the random pages you were just looking at. I want to modify this behavior so that users can access previous random pages via the back and forward buttons.
I don't own the website, so I can't just change the redirect code.
Here's what I've tried, all of which has failed.
Predicting what would be redirected to. While somewhat possible, there would be no way to avoid failure in up to .1% of clicks, and it would react very poorly to unexpected events, like a page that's published a day late, let alone a sit structure change.
Loading the 307 page via ajax. The request stops at readystate == 2 and I can't access the location header.
Cancel the click event and instead set location.href = random_link.href. This has no effect - the new page still doesn't go into history.
Have the new page call history.pushState. This successfully adds the page to history, but I can't find a way to distinguish between new pages and ones being opened via the back button, so the history quickly becomes very corrupted.
Keeping my own history in localStorage. As above, I can't tell when the back button is being used.
I'm working on a solution that I'm pretty sure will work, involving loading the page in an iframe over the existing page and using a background process and messaging to work around the fact that content injections from chrome extensions can't access window.parent from within iframes. And using the history API to reflect the current iframe's URL in the address bar, and get the back and forwards buttons to apply to the current iframe where appropriate.
While I'm pretty sure the last solution can be made to work, it's a hideously complex and heavyweight approach to what seems like a simple problem. So I thought I'd ask you guys before I continue: any other ideas?
Have you tried storing the locations in localStorage, then hi-jacking the back button ?
I am sure you know how localStorage works, for hi-jacking the back button you can refer to this : Is there a way to catch the back button event in javascript?
T.