How do I write OnMouseOut so it closes a popup tooltip? - javascript

I have this code creating a popup/tooltip when specific text is hovered by the user:
function popup() {
$('#example').load("example.html");
}
I add this to make the tooltip appear:
<div id="example" onmouseover="popup(this)" onmouseout="popup.close();">Hover over this!</div>
What that's doing, I'm happy I succeeded figuring out, is when the user hovers over the text "Hover over this!" a window appears and displays example.html as the content of the popup window. I included onmouseout="popup.close();" in an attempt to get it to automatically close.
I'm trying to get it to also close the popup when the user moves their mouse away from the text. I've tried this:
function popup() {
$('#example').load("example.html");
}
function close(){
popup(this).close();
}
Which, obviously to those who know more than me, didn't cause the window to close.
How do I have to write a very simple version of this code correctly so it closes the popup onMouseOut?
I've found this solution that's very similar but I'm not 100% sure how to edit that either to get it loading the external page I want.
Edit: Nope. The solution in the above link didn't work out for me.

I'm not super skilled in JS, so bear with me. It looks like you have a function to display the popup, so I will assume that is working well. I only have a few suggestions, my best one is to have an if/else statement.
If the mouse cursor is over the text, display the popup.
Else, hide the popup.
I don't see a reason why the functions you set up wouldn't be working, so you should just be able to add that. For fear of giving incorrect advice, I will not be showing code because I suck at JS and it will probably be incorrect. But do some research and see if that works. Some other people might have better feedback than me.

First, you have to know the basics of JS.
jQuery is its library/framework, written by an enthusiastic programmers like you. At first, JavaScript.
<div onmouseover="this.innerText='7'"
onmouseout="this.innerText='77'">Hover please!</div>
On mousing over it, the text is 7, on mouse out it is 77 .
This is basic.
And the language is not Java.
JavaScript is easier a little bit.
This is what you got to know now.

The first thing here you have to know is HTML on the web.
Then you get to JavaScript (basically without jQuery at first ).
You were using the jQuery library ajax methods of JavaScript .
<!--normal code (it's a comment!)-->
<script>function getLoad(){return '<iframe src="example.html"/>' }</script>
(return means give out value).
<div onmouseover="this.innerHTML=getLoad()" onmouseout="this.innerHTML='Hover please!'">Hover please!
</div>

Related

Removing Preload Div and JS breaks website

I created a site with a preloader and when I was done decided I no longer want it, but when I remove the code for it, it won't load past it any longer. It just displays a grey box when attempting to access the website.
There's quite a lot of code to show, but I was just hoping someone may be able to steer me in the right direction by telling me what Div is causing this via inspect element.
If there's any snippets of code I can provide please let me know.
The #main id on the upper most div is causing the problem. Consider using semantic elements like main over generic divs.

Selenium clicking button with no name or id

I've been struggling with trying to automate this page. After I login, I'm at this page where I'm supposed to click a button before I redirects me to the next page. The problem is that this button does not have a name or an ID which is making it very difficult to find this element. I've tried mechanize and splinter both. And finally tried selenium but that didn't help either. Really struggling with this. Just need to click this damn button! Any help would be really really appreciated. Love python and automation, but this time nothing seems to be working for me. Please find below a snapshot showing the the code shown when I click on "inspect element". Also, I can't type here the page source code as it is >300000 characters, so you can probably take a look at the page (you'll need to login which takes just 10 seconds). The page I'm referring to is right after you login - http://www.160by2.com/Index
[!Snapshot showing the code I get when I click "inspect element"
[]1
There is class name:
driver.findElement(By.className("da-sms-btn").
Also you can open application in Chrome and copy CSS or XPATH in browser:
Open application in Chrome
Inspect element
Right click on highlighted area
Copy CSS or XPATH
You can try first getting the form by the id, then getting the button by the class name:
wd.find_element_by_id("frmDashboard").find_element_by_class_name("da-sms-btn").click()
You can try to find the element through its xpath. Selenium does a good job of this:
webdriver.find_element_by_xpath("element xpath").click()
You can easily find the xpath by going to the inspect element sidebar on Chrome and right clicking on the element you want. The right click drop down menu should have an option "copy xpath".
I would write a cssSelector as follows and try that.
button[onclick*='aSMS']
Notice, I am doing a partial search with *
Thank you so much for your replies! I was actually able to make it work using splinter instead of selenium! Here's what I did-
1) I just executed the js which was being executed on the onclick event of the button.
jsstring="window.parent.openPage('SendSMS?id="+id+"', 'aSendSMS', 'aSMS', 'ulSMS')"
br.execute_script(jsstring)
2) Subsequently, I was faced with the problem that on the next page, everything was embedded inside iframe, and so find_by_name and all were not able to find elements. For that, splinter provides a nice method (Which is documented REALLY bad, so had to figure it out myself with help from stackoverflow)
with br.get_iframe('iframe_Name') as iframe:
iframe.fill("Element_to_fill_Name","Text_to_fill")
iframe.find_by_tag("TagName")[Index_number].fill("Text_To_Fill")
Worked out brilliantly! Thanks everyone :)

Creating a "box-webpage" upon click

I'm trying to accomplish something that might be relatively simple, but I don't know what I would call it (if there is a specific name for it), hence my searches have proved useless.
What I'm trying to accomplish is simple: I have a page built off off the Masonry jquery plugin (similar to http://designshack.net/tutorialexamples/masonry/demos/masonry.html). All I want to do is that when I click on a specific picture, it creates a "box" that fills up part of the screen and can contain another webpage (to describe the picture) while fading out most of the background. Then when I click outside of the box, it returns to all of my pictures.
I've seen this before, as I'm sure everybody else has, but for the life of me I cannot remember an example to look at or how best to do this. I don't have too much experience with javascript or jquery (which is why I'm asking this), but any help to point me in the right direction, whether it is using javascript or html/css, would be great.
If anybody does get the gist of what I'm describing and can explain it better, then you're more than welcome to edit..
What you need are modal windows.
I know the twitter bootstrap has built a pretty good framework for this:
http://getbootstrap.com/javascript/#modals
If you aren't using the bootstrap directly you might be able to pick out what you need.

Website popout page design

I want to have 4 boxes that can be clicked and pop out with text and can scroll.
Similar to the projects page here: http://www.visionslighting.com
However i would like it to be in html/javascript or similar instead of flash.
i have found this: http://www.dynamicdrive.com/dynamicindex4/imagemagnify.htm
which is exactly what i want only with images.
any help is greatly appreciated.
This is easily accomplished with the jquery-ui. They have a function called dialog that you can tell to be a modal(the box that floats on the screen).
I think you're looking for a javascript lightbox. Check out this one: http://defunkt.io/facebox/
You can find even more here: http://line25.com/articles/rounding-up-the-top-10-jquery-lightbox-scripts

How my select list become uneditable?

I am coding some sort of booking system - calendar. One of the features is also a (js) pop up window with detailed information about event - user can either view them or edit.
Now my problem - I have put there a HTML select control (dropdown box), quite simple - 5 options. But somehow, and I have no ide why, this select is uneditable - that means that after I click on it nothing happens (I do not get the list of the options).
I know that now I should put a code here, however, whole system is so complex that it would take me ages.
I do not await exact answer or solution of my problem. I would like to ask you for advice - what would you check? I went through CSS up and down - no clue at all. Maybe some javascript? But how? I do use one public js library, so it might be something there, I checked as well, no clue.
Any advice would be much appreciated. I am stuck now... :-(
Thanks a lot!
Peter
::EDIT::
I have found out what is was! The ID if that pop-up window is bbit-cal-buddle and there is this line in the .js:
$("#bbit-cal-buddle").mousedown(function(e) { return false });
which basically explains why I can't select anything in dropdown (funny thing - checkboxes and radio works!). So my question is: how do I exclude my select and option tag from that .js command?
I've found a useful option when the bug is that obscure is to logarithmically comment your code.
That is,
Comment 100% of the code that might be causing a problem.
Test
If it works, uncomment 50% of the code you commented and go to step #2.
If it doesn't work, you know the problem exists in the code you uncommented.
Yes, this is somewhat of a monolothic technique, but I've found it to be very useful in the past.
Regards,
-Doug
Just to be sure, turn off ALL styles. this will render your page without the styles(obviously) and check if you can click the drop down. If you can, it is 98% a CSS error. It happened to me awhile ago - most probably an absolutely positioned div is covering it.
If you still can't click it, bring back the CSS then disable all javascripts. It should still be clickable by then since and html select tag doesnt need JS to be clickable.
If it still doesn't work, try doing a regular html select tag and check if you can select that one. If you can, then there is something wrong with your select tag

Categories