Javascript running in facebox window - javascript

I'm modifying a website to have a pop up box appear when a user rates something prompting the user to login. Unfortunately the login process is something that I don't control and it uses a whole heap of javascript and redirects to do it and it seems that the javascript is failing.
Can javascript run in the modal box or is there a way around this?

You could try isolating the JavaScript by putting it in an inline frame [iFrame] on a separate html document
Just a thought. Haven't tested it.

Related

How to Manage non-JS popups in Selenium?

I am currently working on testing a site and one of the issues I am running into is working with a non Javascript popup.
I have tried using the Selenium Alert interface.
Sample of what I have done
Alert a = WebDriver.switchTo().alert()
alert.accept()
alert.dismiss()
This seems to work for Javascript pop up alerts but not for non javascript pop up alerts. Is there any way to deal with pop ups with Selenium that aren't Javascript based?
Last time I ran into a pop-up like this, it was a frame that was otherwise "invisible." Open the page with your favorite browser, highlight something in the pop-up, right-click it and choose Inspect Element, then follow its XPath. You may have to switch frames a few times in Selenium to get where you need to be.
If its HTML popup then no specific thing needs to be done, just locate required element normally just like you do for normal web page.
But if its saying element not found then there can be 2 cases:
popup is present inside an iframe
before this popup you were inside iframe but that pop up is present in defaultContent View.
Depending on case, use these solutions:
For #1 : driver.switchTo().frame(0); //Here 0 means first iframe, you can use iframe id also
For #2 : driver.switchTo().defaultContent();

How to trigger a click event of a button with javascript on an arbitrary site

I need to navigate through a particular website, frequently, to get at some sub-page that is several layers beyond the front page and it is taking too much time to click and scroll and click and scroll to get at the desired final screen where I enter the search string. So, I would like to automate the process by making Javascript trigger the right button events to get me to the distant page where I can enter the search string manually.
So, I know how the code needed to trigger the event,
document.getElementById('x').click();
but how can I implement this inside my browser, since this is not my own website?
If this is going thru different pages, then probably a Web UI automation tool would be the best (like Selenium - http://www.seleniumhq.org).
as #elcarns says, if you need to inject code into another's website, you could do so opening the console (view --> developers --> javascript console in Chrome).
Another, more complex way to do it when you have to traverse several pages is by developing a plugin.
javascript:document.getElementById('x').click(); in the url bar. You can probably make a bookmarklet for it as well.

Find script responsible for opening a new window

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

How do I detect the client has javascript turned on/off from Rails?

I don't want to deal with users who have javascript turned off, so I want to just prevent them from using my application. I want to detect if the user has javascript turned on so I can redirect them to a page that tells them they need to use javascript. I'm sure its in the request header. Anyone have any ideas how I can do this?
The noscript tag is the easiest solution, though not exactly whay you're looking for.
<noscript>Get outta here.</noscript>
Do you really need a redirect at all? Put the message in a <noscript> element, and it will only be displayed to those it applies to.
You can't. The server has no idea what the client has enabled. You can't even "detect" if Javascript is disabled from the client (because what would you use to do so?).
You can use tricks to show content when Javascript is disabled (for instance, a <noscript> tag, or using Javascript to hide content that is meant for JS-only).
There is no way to detect JavaScript on the server side. However, you can use a NOSCRIPT tag to display a message indicating that your website requires JavaScript.
For an example, turn JavaScript off in your browser and load a Stack Overflow page. There'll be an obnoxious red message across the top of the page warning you that the site works best with JavaScript enabled. You can examine the Stack Overflow source code and CSS styling to see how they implemented it.
If you really want to deter non-JavaScript users from using your website, you could put your message in a div inside the noscript tag and expand the div to cover everything on the page.
You only need html:
<noscript><meta http-equiv="refresh" content="0;url=http://example.com/use_js.html" /></noscript>
This of course won't prevent the server from serving content, it only will output this meta refresh tag, which will be parsed (and executed by redirecting the user) by clients that got no javascript or javascript disabled.
You could have a landing page with a snippet of javascript that runs and redirects to the real railsy landing page, or perform an AJAXY call to get the data you want to show the user. This would positively require javascript to be enabled to continue.

How to embed functionality into HTML email?

We want to let users click a thumbs up or thumbs down button from an HTML email, without causing the clicking to open a browser window.
Is there a way to essentially embed limited web functionality (i.e., clicking an icon, showing confirmation) within HTML emails?
Thanks!
I'm afraid such functionality, while theoretically possible, wouldn't be very practical given that most email clients strip out or disable JavaScript in order to prevent malicious code execution or other security issues. Your best bet is to use an image that looks like the thumbs up or thumbs down and then links directly back to your website. The browser window will still need to be opened, but you'll at least achieve the main part of your goal.
The short answer is no, not reliably across email clients. Usually with something like this I'd embed an image that looked like your functional element and just have it link to a web page that has that functional element.

Categories