Extend div outside bounds of iFrame? - html

Is it possible to extend content beyond the bounds of an iframe?
In my case, I was formerly rendering a native <select> control inside of an iframe. As a native control, when it rendered, the dropdown was able to occupy space outside of the iframe. I recently converted the dropdown to use select2, which rebuilds the dropdown using various <span> elements.
The problem is now it gets cutoff within the <iframe>:
I've tried setting the overflow to visible, but that doesn't work:
iframe {
overflow: visible
}
Here's a Test Case on Plunker
JavaScript:
$("#OpenSelect2").click(function(){
OpenPagePopup("select2.html", "Select 2", 150, 400);
});
//Open Diagnosis Control for editting
function OpenPagePopup(location, title, ht, wt) {
$('<div>')
.append($('<iframe/>', {
'class': "fullFrame",
'src': location
}))
.dialog({
autoOpen: true,
modal: true,
height: ht,
width: wt,
title: title
});
}
index.html:
<button id="OpenSelect2">Open Modal with Select2</button>
select2.html:
<select class="select2">
<option value="AZ">Arizona</option>
<option value="CO">Colorado</option>
<option value="ID">Idaho</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NM">New Mexico</option>
<option value="ND">North Dakota</option>
<option value="UT">Utah</option>
<option value="WY">Wyoming</option>
</select>
<script >
$('.select2').select2();
</script>
Possible Workaround:
DON'T USE IFRAMES! Yeah, I know, I know, but this is the situation I find myself maintaining.

No. There is no way to extend content outside of an iframe. Think of it as another browser window entirely.
The reason that the options will extend below the iframe is that form elements follow their own rules. They differ from browser to browser, and for some of the elements you can't change the styling. When you use select2 it turns the form into a regular element (not a default form element), so you can manipulate the style. Unfortunately, this also makes it confine to the iframe.
Consider that a browser can also do this (but it doesn't mean you can):

Being that the short answer is no, it's worth pointing out that it's not always necessary to load external content via an iframe. If, for example, you're working in PHP, you can simply call file_get_contents($filename) to simply plonk the desired content onto the current page.
This will clearly be limited to relatively straightforward HTML, but it certainly has its uses.

Related

How to do pagination in select box based on scroll

HTML
<select class="form-control choice requiredField" id-available name="SelectData" ng-model="box.box_id" title="Select">
<option value="" disabled selected>{{'_SELECT_BEACON_' | i18n}}</option>
<option value="{{y.box_id}}" ng-repeat="y in dataList" class="nms">{{y.beacon_code}}</option>
</select>
ANGULARJS
boxService.listUnassignedDevice(function(res) {
$scope.dataList = res;
}, function(error) {
});
Here I have large data in "dataList"(10000>). So I need to list data in select box after mouse scroll down. First I have to show 100 data, when mouse scroll down, I need to show next 100 data from API.
you can use ngInfiniteScroll directive and add script tag then add module 'infinite-scroll'and then Use the directive by specifying an infinite-scroll attribute on an element.
<div infinite-scroll="myPagingFunction()" infinite-scroll-distance="3"></div>
ngInfiniteScroll will call myPagingFunction() any time the bottom of
the element approaches the bottom of the browser window. See the API
documentation for more information about what attributes are available
for use, and take a look at the demos to see ngInfiniteScroll in
action.

Selecting a style sheet through a dropdown menu

So I have my site set up to have two different themes, and that works wonderfully, but when I'm making a lot of changes, I can miss some stuff and things start to not look the same.
This is how I'm doing that:
<select onchange="window.location=this.value">
<option>Default</option>
<option value="http://MyWebsite.com/Cyan/">Cyan</option>
</select>
What I WANT to do, is just have two separate style.css files and have the dropdown menu request the one you choose.
This would make my job so much easier, but I'm not 100% sure how to do it. Would I simply replace the website link with the stylesheet? Is there even a way to do this?
One possible solution using jquery:
$("select").on("change", function(){
$("<link/>", {
rel: "stylesheet",
type: "text/css",
href: $(this).val()
}).appendTo("head");
});
There's a framework that deals with this kind of thing. Coupled with jQuery it could be pretty good. It's utils.js, available there.
Your HTML should look like this:
<link id="stylesheet" rel="stylesheet" href="path/to/theme1.css" />
...
<select id="dropdown">
<option value="path/to/theme1.css">Theme 1</option>
<option value="path/to/theme2.css">Theme 2</option>
</select>
And then your script:
$("#dropdown").on("change", function(){
var path = $(this).val(); // Get path from selected option
utils.changeStylesheet("stylesheet", path);
});
Should work fine, though I haven't checked the documentation so the utils statement may need revising...

Dropdown Menu Options are Image (not text)

I want to ask about html dropdown menu. As we know, that option tag in html only support text. However, I need to create a drowp down menu that show list of image. I've searched for it. And I found several ways, including using css or jquery. However, that's not what I want. Here is, what I want to create:
<option value = blablabla><img src = "img/blbalba.txt"></option>
The code above is not working. Is there any sugestion to display dropdown menu like that?
Thank you for your help.
As You can't do that in plain HTML, but you can do it with JQuery.
Right now You can do like this
<select>
<option value="img1" style="background-image:url(images/img1.png);">image 1</option>
<option value="img2" style="background-image:url(images/img2.png);">image 2</option>
<option value="img3" style="background-image:url(images/img3.png);">image 3</option>
<option value="img4" style="background-image:url(images/img4.png);">image 4 </option>
</select>
Browsers will only render text inside a select tag, so, if you wan to use a selector that shows images instead of text, you cannot use a select you'll need to build your own selectable object.
That could be quite difficult to do. You can use different premade solutions that people on your situation developed before or try to reinvent the wheel.
Check this :)
A free light weight jQuery plugin that allows you to create a custom drop down with images and description.
What is so cool about this plugin!
Adds images and description to otherwise boring drop downs.
Allows JSON to populate the drop down options.
Converts your HTML select element to ddSlick.
Uses Minimum css and no external stylesheets to download.
Supports callback functions on selection.
Works as good even without images or description!
http://designwithpc.com/Plugins/ddSlick#demo

Chrome bug on select element dropdown when many options are hidden

I'm looking for a workaround for a rendering bug in Chrome. It shows up when a select element has about 90%+ hidden option elements. In Chrome, the dropdown height becomes too short to use. This does not appear to happen on other browsers. View example on jsFiddle.
HTML Example
Note: Some options were removed to keep the code brief.
The bug does not show up unless all options are present.
100 Options, 90% Hidden:<br>
<select>
<option value="">Select an Option</option>
<option value="0" style="display: none">Option 0</option>
<option value="1" style="display: none">Option 1</option>
<option value="2" style="display: none">Option 2</option>
<option value="3" style="display: none">Option 3</option>
<!-- Options removed for brevity. -->
<option value="86" style="display: none">Option 86</option>
<option value="87" style="display: none">Option 87</option>
<option value="88" style="display: none">Option 88</option>
<option value="89" style="display: none">Option 89</option>
<option value="90">Option 90</option>
<option value="91">Option 91</option>
<option value="92">Option 92</option>
<option value="93">Option 93</option>
<option value="94">Option 94</option>
<option value="95">Option 95</option>
<option value="96">Option 96</option>
<option value="97">Option 97</option>
<option value="98">Option 98</option>
<option value="99">Option 99</option>
</select>
Browsers Tested:
Chrome 27 & 28 (Fail)
Firefox 21 (Pass)
IE 9 (Pass)
Opera 12 (Pass)
Safari 5.1 (Pass)
View Example on jsFiddle
Alternate Example Link
Update: I did some reading on the subject, and apparently options are not supposed to be hidden within a select. You can disable options, but they will not disappear. If you don't want an option to be in the select at all, you're supposed to remove the node entirely. The ability to hide options doesn't appear to work completely cross-browser, and in most you can continue to select the "hidden" options by using the arrow keys. I need to toggle options on and off, which makes this inconvenient to my particular situation, but this appears to be the only method that will work thus far.
Adding this might be considered a workaround:
$(document).ready(function () {
$('#ph2').mouseenter(function () {
var html = '';
$(this).find('option').each(function () {
if ($(this).css('display') !== 'none') {
html = html + '<option>' + $(this).text() + '</option>';
}
});
$(this).html(html);
})
});
Here's the jsFiddle; I'm using jquery just for simplicity. In this case, I'm just redoing the HTML on mouseenter. It's not ideal but it could get you going further. Also, note that you have ph2 set up as a div in your HTML; I think you should set it as a select element from the start and on the fiddle you can see the change I made to the html. But overall, until the bug is fixed, I think something like this is going to be as close as you'll get to having a working option.
The problem is already active on all major browser (Edge, Chrome, Opera,....) but Firefox.
The problem arises as soon as the number of hidden items is greater than 1000.
Be careful, because with just 100 items, all browser seem to work
The problem also disappears if the active items (not hidden, not disabled) are at the top of the list.
More exactly, when you click on the "select" input field, the browser open a list with a number of rows that is equal to the number of active items included in the first 1000 item.
For example, if you build a list of items with first x items active, then y items "inactive" (where y if greater than 1000) and then again z items active, you will see a list wide x rows with x+z items.
By the way, a workaround to the problem could be the sorting of the items list
This behaviour has been verified on Chrome, Opera, Edge
As a workaround for this bug I can propose the following solution:
To hide an option 'convert' it to some other tag and hide it with .hide().
To show an option 'convert' it back to option and show it with .show().
For 'conversion' we need something like this: https://stackoverflow.com/a/9468280.
Example:
// some `replaceTagName` implementation here
// hiding options
$('.option-selector').replaceTagName('span').hide();
// showing options
$('.option-selector').replaceTagName('option').show();
A bit heavy but working :)
I had this problem and this is what I did:
var originalSelect = $("#the_select").clone();
function hideSomeOptions(){
$('#the_select .hide_me').remove();
}
function restoreAllOptions(){
$("#the_select").replaceWith(originalSelect[0]);
}
The target select input has the ID "the_select" and the options or optgroups that need to be toggled have the "hide_me" class.
I found that the order of the hidden/visible options make a difference. It is like chrome stops counting for the height for the drop down at the first hidden option. One way around is to move the shown options to the top of the select. If you are using jquery something like this.
var select = "select#MySelect";
$(select).children("option").hide(); //hide all options
$(select).children("Selector for items to show").each(function(idx, elm) {
$(elm).parent().prepend(elm); //move item to the top of parent
});
$(select).children("Selector for items to show").show(); //show selected options
I ran into the same problem (Chrome 40) and found that the following workaround works well for me.
var originalOptions = [];
$(document).ready(function(){
originalOptions = $("yourSelect").children("option");
$("someElement").someEvent(function(){
$("yourSelect").children("option").remove();
$(originalOptions).each(function(){
if(/*criteria here*/){$("yourSelect").append($(this));}
});
});
});
The best fix is to add at the end on the last
<option></option> in your Select Element. Add this code:
<optgroup></optgroup>
This will add a blank group element, and for now is the best Easy and fast FIX to this rare BUG.
Thanks!

Using page anchors in <Select> dropdown list in html

I have a static HTML page that contains a lot of tables. I would like to use the html tag <select> to create a simple dropdown menu which jumps to a specific table further down the page.
What command sets the user selection to jump down the page and what anchor code is required to give that selection a target.
I believe you just need to use JavaScript to make it so when you click/change value on the select box it takes you to the link specified in the value of that select option.
<select name="dropdpown" size="1" id="select-anchor">
<option value="#link">foo</option>
<option value="#link">bar</option>
</select>
And using jQuery library for the JavaScript functionality simplifies things (and will other JS related features of your web project)
$(document).ready(function () {
$('#select-anchor').change( function () {
var targetPosition = $($(this).val()).offset().top;
$('html,body').animate({ scrollTop: targetPosition}, 'slow');
});
});
Here's a jsFiddle of it in action.
You can't do that without JavaScript. Nor you should.
I, as a user, expect to select a value from a dropdown list. Select one item between others. Not act as navigation.
One can argue that it's OK if done for a mobile browser, but that's still bad UX.
This is how it can go to a link on select:
<select onchange="window.location.href=this.value" >
<option value="search.php?perpage=10">10</option>
<option value="search.php?perpage=20">20</option>
<option value="search.php?perpage=50">50</option>
<option value="search.php?perpage=100">100</option>
</select>