HTML CSS: Iframes/Dynamic Problem - javascript

I am having some trouble creating a experimental 'dynamic' style website. The site is set up as follows. The user has a menu of links to choose from, specifically using an image map. When they hover over a selection, an iframe pops up (becomes visible) displaying some data. When the user removes the mouse the iframe goes away, until the user hovers over another link.
-- It seems to be working well, but only intermittently. Sometimes after leaving one of the anchors, the syle, text etc. still occupies the frame even after i hover over another link. This behavior seems to be fairly random, but there must be a way to fix it.
Here's an example of what i'm using. The show function sets the frame to visible if the argument is a 1, and hidden if 0. frameset sets the main frame to the desired html document. I tried implementing a reset to set the frame to something blank after leaving the link to try and fix it, but the problem persists.
<area shape="circle" coords="..." href="..." onmouseover="Show('frame', 1);
frameset('page.html');" onmouseout="Show('frame', 0); reset();" />
And the functions
function frameset(a)
{
document.all.frame.src=a;
}
function reset()
{
document.all.frame.src=blank.html;
}
It's a very hard problem to describe, so let me know if more information or code is needed. Any better alternatives to my method are also welcome, considering i'm not fluent in javascript :)
Thank you

I think what you are doing could be performed better by using a more modern approach.
The image map could have absolutely positioned block level anchor tags.. but this doesn't seem to be the problem.
Instead of using iframes, I'd recommend using AJAX to get the information and a framework like jQuery to help you display the data.
You could load the AJAX and display the box with a loading throbber (http://www.ajaxload.info) on mouseover, and parse the data into viewable format inside the div.
Learning AJAX
AJAX is when a page makes a http request to the server and can also return data which is then used with Javascript to update the DOM.
jQuery is a Javascript framework designed to abstract away browser specific code and inconsistencies and just make using Javascript a better experience.
Check out jQuery's AJAX functions
Good luck!!

Related

Using javascript to alter element's CSS display property works inconsistently on Chrome

I've got what should be a fairly simple "please wait" overlay that should pop up during a variety of different tasks on a data-review/dashboard website I'm working on (data queries, chart rendering using ChartJS, putting data into a file for download, etc.) that is not consistently working as desired in Chrome.
I toggle the overlay via Javascript at the beginning and end of each function that I need it for. The overlay successfully displays/turns off on IE11 and Firefox every time I do a function that calls it, but on Chrome it is consistently inconsistent (ALWAYS displays during specific functions, NEVER displays during other functions) despite calling the same few lines of code every time. When it does not display, the console confirms that the method to toggle it is being called and I can see the page's HTML update, but the user's display does not change.
The functions that the overlay does not display for involve creating/updating ChartJS charts, including an AJAX call to get data. I have functions that the overlay displays properly on that involve just doing AJAX requests. On the functions where it does not display, it never shows up on the user's screen at all, even well before I get to ChartJS stuff. It's confusing as heck. I can give out a little of that code if it would be useful, but again since the overlay never even shows despite toggling the overlay as the first line of those functions, I don't think that's the the problem...
It's a style thing more than a function thing; I also disable other user-interface elements while the overlay is supposed to be active (which Chrome's display also does NOT reflect but again definitely occurs). But I'd still like the overlay to consistently display, particularly since those ChartJS functions can take a few seconds, and I'm wondering if people have any ideas.
HTML for overlay, as it appears on page-load
<div id="overlay">
<img src="img/loader.gif"></img><br><strong>Data loading, please wait</strong>
<div id="overlayAdditonalMesages">
</div>
</div>
Javascript for overlay toggle
function overlayToggleOn(additionalMsg) {
console.log("overlay should be on");
document.getElementById("overlay").innerHTML = '<img src="img/loader.gif"></img><br><strong>Data loading, please wait</strong>'+additionalMsg;
document.getElementById("overlay").setAttribute("style", "display: flex;");
$("overlay").show(); //just trying to fix the thing with Chrome
}
function overlayToggleOff() {
console.log("overlay should be off");
document.getElementById("overlay").innerHTML = '<img src="img/loader.gif"></img><br><strong>Data loading, please wait</strong>';
document.getElementById("overlay").removeAttribute("style");
}
Like I said, should be simple, and I struggle to understand why it's not working consistently in Chrome. Thoughts appreciated.
Why using .setAttribute() for you inline styles.
I also saw where you added a closing tag for your image element </img> why?
Use
id.style.property = value
Instead of setAttribute()

z-index for jquery object issue

First off, I am sorry in advance- anyone who reads this is going to hate me.
So, I am currently finishing a webpage for a client. Things are going decently, except I'm having a bit of an issue with the positioning of an element. There is a little contact box that is supposed to slide in from the side when you click on it. The issue is that I basically have had my hands tied, and I have to use wordpress for this page, and this contact box is a plugin that the original author of this page chose. For some reason- this contact box always ends up behind other elements. I tried setting the z-index in the source code of the plugin by finding the name of the variable that is supposed to hold the instance of the slider- and I could not get anything to work (partially because I havent used jquery in a while, and, this isn't my plugin). I tried using the .zIndex function, but, it kept throwing errors. So, I went to CSS. I got the IDs of the wrapper and the actual box itself, and set their z-index to 100. This did nothing, which has left me stumped. Unfortunately, I can only provide links to the site, and a pastebin of the plugin's code- since the source code for the website is huge... and I also dont actually have access to the server- only the WordPress admin page (which doesnt allow me to edit the source of pages)
http://pastebin.com/NX8AnB16 - pastebin of the plugin source
http://buyinghouseinusa.com/ - the site i am currently trying to finish
If anyone could help me figure out what I need to apply the z-index to to make the stupid contact form stay on top, I would be very greatful. I apologize for the inconvenience of not having the actual code offhand (with the exception of what the browser can show me)
z-index only applies to positioned elements.
Then, in order to make div.dwp-contact-wrapper{z-index: 2000} work, you need
div.dwp-contact-wrapper {
position: relative;
}

Building a "single page" site with animation between pages

I would love to know what is used to have an effect such as this website template: http://www.templatemonster.com/demo/43491.html
I would like to have a single menu and background while once I click on the menu link it triggers the new page to slide into view without being redirected to a new page causing the browser to reload the new page, etc. Something smooth and nice.
I'm not looking for code (other than the functions to use (if JQuery)) and what effects should I be looking for to make this possible?
Just point me in the right direction :)
There are many ways to achieve what you wish, but this is my suggestion on how to go about it conceptually:
Animate the content by animating the position of your content container, that should give a nice smooth feeling to your page. The jQuery documentation should be pretty clear on that. Remember that you want to intercept the normal behaviour of the anchor, so either preventDefault() or return false, or both.
Get your content using an AJAX request. You can use the href attribute that you put in your link in order to fetch the correct content. Then bind an event to that <a> element with a the .on() method. The reason why you leave the href is to have a graceful fallback: should something go wrong with the code, should the user have javascript disabled, or simply navigating on a non-javascript friendly browser, he will still be able to access your content.
These are the two essential steps to achieve what you are looking for. If you want to fine tune your site a bit more, try to think about those things as well:
Make your website look more responsive by the cautious use of loading .gifs.
Don't double serve content: check whether the user is clicking to the link of the currently displaying page and don't fetch the content again; besides looking silly to your user, it will make a useless server load (probably insignificant, but still). Always consider your user, though! Tell him that that link is disabled by clever use of UI.
Manipulate browser history: using the history API. Your site will be more accessible, more user-friendly, more SEO-friendly, and will also look much more advanced.
now there can be tons of ways .. the easy way (but it's not much of a maintainable way )
is to all your website content in one page and wrap every section that you consider a page in a div like so
<div class="home-page">content of home page goes here </div>
<div class="contact-us-page">content of contact us page goes here </div>
etc...
and with jquery hide them all except the home page
$(function(){
$('.contact-us-page').hide();
$('.other-page').hide();
})
and when the user clicks on the link to other page let's say the contact us page you will hide the parent and slide the contact us page instead
$('.contact-us-link').click(function(){
$('.home-page').hide(1000);
$('.contact-us-page').show(1000);
})
and thats it :)
the down fall of this is that there will be no routing ..
so to solve this you have to use something like backbone.js
which takes a while to know it well ...
this is just a quick idea on how this works ..

Issue with IE7 hiding/removing/showing content using jQuery

So I have a bit of script at the bottom of my page //RETAINER CURRENT that is supposed to hide and show content based on what menu item the user selects in the maincontent area. Unfortunately in IE7 all layers are rendered which means the videos in each layer play simultaneous. I tried .detach, .remove, methods and had no luck and when I saved the items to an array and .empty 'd them I still had no success. What noob mistake am I making?
http://jsbin.com/ahuye4/3
I had the same issue. I was using asp.net so the way I was able to solve this was by using updatepanels and handling the hiding/showing in the code behind with Panels.
I'm not sure what fraemwork/language you are using.
However, I think you might need to call into the flash object and pause/stop the flash videos programmatically.

Javascript context menu for images

I have a website where lots of people copy images off it, which is fine. What I do want to do, however, is help them embed it on the target website they are going to.
Ideally this would take the form where when a user right clicks the image a context menu will appear giving them easy options to embed or share the image.
What is the best way to do this?
P.s. I don't care about them hotlinking, or saving the images at all, all I want to do is provide the user with an easier way to share the images!
Don't send the image to their browser.
No. You can prevent the common user from bothering, but the fact is the URL is sent to the browser to download. So at the very least I could view the source and figure it out.
If you really want to try to annoy the user, though, you can attach an oncontextmenu event which will capture the right-click in some browsers.
edit:
In response to your comment..
Since you're using jQuery, you can use this plugin to detect right clicks. It has been tested on most browsers.
You can then use something like SimpleModal to display the modal box you want to show the user..
$('img').rightClick(function (e) {
$.modal(...);
});
You can actually render HTML as embedded mime data in all major browsers except for IE:
http://jimbojw.com/wiki/index.php?title=Data_URIs_and_Inline_Images
Another weird, but workable solution is to convert the image to CSS:
http://elliottback.com/wp/convert-image-to-css/
Neither is really that great a solution, but it highlights the fact that you need to be willing to lose an image by just putting on the web.
Even if you use a plug-in, people can just do a screen capture.

Categories