IE8 iframe onload not firing - iframe

I'm returning the following from a controller that in all current browsers ff, chrome and IE10 results in my iframe firing it's onload event:
return new ContentResult { Content = "", ContentType = "text/html", ContentEncoding = System.Text.Encoding.Unicode };
But in IE8 it does not work, I've been working under the assumption that it was my client side code that was broken and not adding a listener on to the iframes onload event, but I'm using code from Nicholas C. Zakas:
var oIFrame = document.createElement('iframe');
oIFrame.style.display = 'none';
if(oIFrame.attachEvent)
{
oIFrame.attachEvent('onload', fnIFrameCallback);
}
else
{
oIFrame.onload = fnIFrameCallback;
}
document.body.appendChild(oIFrame);
does anyone know if IE8 requires some actual content to be returned from my controller rather than just empty Content=""

This code works fine in IE 8...
function fnIFrameCallback(){
alert("test iframe is now loaded.");
}
function loadLocalIframe(){
var oIFrame = document.createElement('iframe');
oIFrame.style.display = 'none';
if(oIFrame.attachEvent)
{
oIFrame.attachEvent('onload', fnIFrameCallback);
}
else
{
oIFrame.onload = fnIFrameCallback;
}
document.body.appendChild(oIFrame);
}

Related

How to disable button with Response Redirect

I Have two pages, Pages A and Pages B, in Pages A i have button which one will redirect to Pages B, then i try to back to Page A using button from browser.
Please your suggestion, how i can disable my button in Page A for not redirect again to Pages B.
OK. If you want to disable the browser's back button feature, then you can try the below JavaScript: Put it in the head tag of the Sign Up page
<script type="text/javascript">
function noBack() { window.history.forward() }
noBack();
window.onload = noBack;
window.onpageshow = function (evt) { if (evt.persisted) noBack() }
window.onunload = function () { void (0) }
</script>
Note: This will only block the feature of browser's back button but if you manually go back to the Sign Up page writing in the address bar, this then will not work.
One more thing, as you are using Session, you can integrate it with the JavaScript as follows:
<script type="text/javascript">
var someVar = "Hello";
//var someVar = <%=this.Session["UserId"]%>; //Keeping the session value in JavaScript variable
function noBack() {
if (someVar == "Hello") { //You can use - if (someVar != null)
window.history.forward()
}
}
noBack();
window.onload = noBack;
window.onpageshow = function (evt) { if (evt.persisted) noBack() }
window.onunload = function () { void (0) }
</script>

redirect chrome users in new window

I have tried this but its not what I want ....
also this code does not works
<%= Html.ActionLink("Paypal", "HowItWorksRedirect", null, new { #class = "Paypal" })%>
public ActionResult HowItWorksRedirect()
{
return Redirect("https://www.paypal-deutschland.de/sicherheit/schutzprogramme.html");
}
I want to redirect all chrome users to new window
I want to keep users on my website but also redirect them to new window... (600x800 or something like this)
How can I do that?
Opening a new window (or tab, depending on browser settings) is easy:
With a link, you can use
LINK
Or you can use JS:
window.open('http://google.com', 'Google', 'width=800, height=600');
With the help of navigator.userAgent you can get the User Agent and use a regex to find out if the user is using Chrome
if(/Chrome/.test(navigator.userAgent)) { /* CHROME USER */ }
<script>
//specify page to pop-under
var popunder="http://wow.ge/"
//specify popunder window features
//set 1 to enable a particular feature, 0 to disable
var winfeatures="width=800,height=510,scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0"
//Pop-under only once per browser session? (0=no, 1=yes)
//Specifying 0 will cause popunder to load every time page is loaded
var once_per_session=0
///No editing beyond here required/////
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function loadornot(){
if (get_cookie('popunder')==''){
loadpopunder()
document.cookie="popunder=yes"
}
}
function loadpopunder(){
win2=window.open(popunder,"",winfeatures)
win2.blur()
window.focus()
}
if (once_per_session==0)
loadpopunder()
else
loadornot()
</script>
but browsers blocking that !

Browser close event [duplicate]

This question already has answers here:
Fired an event in asp.net when Session expired or browser close
(2 answers)
Closed 9 years ago.
Is there any other option except javascript to fire the Session_End() event when a user directly closes the browser without log off. If I all time check that the client give request to the server or not coz I think when user closes the browser, the server gets no request. So if it is possible how can I implement it? Moreover can I always check if the user is viewing any of my pages and if not can I raise Session_End() event?
No, you can't check what the user is doing or when he closes the browser.
This would clearly violate against user and data-security rights of the user. Also such a feature would be browser-dependent and therefor hard to implement because every browser has its own interfaces and philosophies.
What you can do is to implement a function in javascript, that sends a signal to your server every minute or so, telling the server that the user is still active.
You can then store the time of the last signal of the user. That way you see that a user was inactive if you haven't received a signal in the last minute or so.
hii there is one event in javascript to find the browser close event.
but its not work with all browsers.
their is the example.
<HEAD>
<TITLE> TEST</TITLE>
</HEAD>
<script type="text/javascript">
javascript:window.history.forward(1);
var temp = true;
document.onkeydown = keyDownPress;
document.onmousedown = keyDownPress;
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
//alert(is_chrome);
if(is_chrome){
window.onbeforeunload = function(e) {
// confirmExit(e);
alert("1");
alert("2");
alert("3");
return "You are going to close?"; // you can make this dynamic, ofcourse...
}
}else{
window.onbeforeunload = confirmExit;
}
/*if (navigator.userAgent.indexOf('AppleWebKit') > -1) window.onbeforeunload = confirmExit;
else Event.observe(window, 'beforeunload', confirmExit);*/
/*
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if(is_chrome){
window.onbeforeunload = function(e) {
confirmExit(e);
return "Are you sure you want to leave this page ?"; // you can make this dynamic, ofcourse...
};}else{
window.onbeforeunload = confirmExit;
}*/
/* if (window.addEventListener) { // all browsers except IE before version 9
window.addEventListener ("beforeunload", OnBeforeUnLoad, false);
}
else {
if (window.attachEvent) { // IE before version 9
window.attachEvent ("onbeforeunload", OnBeforeUnLoad);
}
}
*/
/* function(e){
if(temp==true ){
alert("You are going to close");
// return null;
}
}; */
function keyDownPress(e)
{
var evt = e || window.event;
var keyPressed = evt.which || evt.keyCode;
if (keyPressed==116) {
temp=false;
return false;
}
if(evt.button==2) {
alert("For security reasons, Right click has been disabled!");
return false;
}
}
function confirmExit(e){
// alert("ok ok ");
if(temp==true ){
alert("You are going to close");
}
}
This is code is working fine in IE 8 , Mozilla FF 8
not working on Google Chorme and FF 9

how to find ID of the control which is present in defualt.aspx in different page defualt2.aspx

I have a web form which load 100 000 of data from the database.I Have 50 dropdown which is populated with respect to selectedindex change of dropdown .so to bind dropdown i am using ajax code .
I have written nearly about 200 line of ajax code in a separate js file.I am using 3 tier artitecture .I am not returning dataset from the bal class, am returning generic class to bind gridview.also i have created a class to bind the gridview.Also I am not using any update panel.
Is this approach will improve my performance.??
But there is a problem for me,i have to write code in js file to bind dropdown like this.
function GetAppStoreLnk(id) {
var txtnameid = document.getElementById(id);
CreateXmlHttp();
var requestUrl = "Default2.aspx?id="+txtnameid+"";
if (XmlHttp) {
XmlHttp.onreadystatechange = function() { getschemename(txtnameid) };
XmlHttp.open("GET", requestUrl, true);
XmlHttp.send(null);
}
}
function getschemename(id)
{
// To make sure receiving response data from server is completed
if(XmlHttp.readyState == 4) {
// To make sure valid response is received from the server, 200 means response received is OK
if(XmlHttp.status == 200) {
var strData = XmlHttp.responseText;
if(strData != "") {
var arrscheme = strData.split("|");
id.length = 0;
for(i=0; i<arrscheme.length-1; i++) {
var strscheme = arrscheme[i];
var arrschnm = strscheme.split("~");
id.options[i] = new Option();
id.options[i].value = arrschnm[0];
id.options[i].text = arrschnm[1];
}
} else {
id.length = 0;
id.options[0] = new Option();
id.options[0].value = "";
id.options[0].text = "Scheme Name is not available";
}
document.body.style.cursor = "auto";
}
else {
id.length = 0;
id.options[0] = new Option();
id.options[0].value = "";
id.options[0].text = "server is not ready";
document.body.style.cursor = "auto";
}
}
}
but if i make class to bind the dropdown this will reduce my js file code line .How will i find the ID of the dropdown in the different page ie Default2.aspx .
Please help me .
How will i find the ID of the dropdown in the different page ie Default2.aspx .??Also i want dont want to use usercontrol or masterpage.
I don't understand your question. You are trying to access the Asp.net drop down in page Default.aspx in the page Default2.aspx right?
Could you please clarify your requirement?

asp.net mvc - how to update dropdown list in tinyMCE

Scenario: I have a standard dropdown list and when the value in that dropdownlist changes I want to update another dropdownlist that exists in a tinyMCE control.
Currently it does what I want when I open the page (i.e. the first time)...
function changeParent() {
}
tinymce.create('tinymce.plugins.MoePlugin', {
createControl: function(n, cm) {
switch (n) {
case 'mylistbox':
var mlb = cm.createListBox('mylistbox', {
title: 'Inserts',
onselect: function(v) {
tinyMCE.execCommand("mceInsertContent",false,v);
}
});
<% foreach (var insert in (ViewData["Inserts"] as List<String>)) { %> // This is .NET
yourobject = '<%= insert %>'; // This is JS AND .NET
mlb.add(yourobject, yourobject); // This is JavaScript
<% } %>
// Return the new listbox instance
return mlb;
}
return null;
}
});
<%= Html.DropDownList(Model.Record[184].ModelEntity.ModelEntityId.ToString(), ViewData["Containers"] as SelectList, new { onchange = "changeParent(); return false;" })%>
I am thinking the way to accomplish this (in the ChangeParentFunction) is to call a controller action to get a new list, then grab the 'mylistbox' object and reassign it, but am unsure how to put it all together.
As far as updating the TinyMCE listbox goes, you can try using a tinymce.ui.NativeListBox instead of the standard tinymce.ui.ListBox. You can do this by setting the last argument to cm.createListBox to tinymce.ui.NativeListBox. This way, you'll have a regular old <select> that you can update as you normally would.
The downside is that it looks like you'll need to manually hook up your own onchange listener since NativeListBox maintains its own list of items internally.
EDIT:
I played around a bit with this last night and here's what I've come up with.
First, here's how to use a native list box and wire up our own onChange handler, the TinyMCE way:
// Create a NativeListBox so we can easily modify the contents of the list.
var mlb = cm.createListBox('mylistbox', {
title: 'Inserts'
}, tinymce.ui.NativeListBox);
// Set our own change handler.
mlb.onPostRender.add(function(t) {
tinymce.dom.Event.add(t.id, 'change', function(e) {
var v = e.target.options[e.target.selectedIndex].value;
tinyMCE.activeEditor.execCommand("mceInsertContent", false, v);
e.target.selectedIndex = 0;
});
});
As far as updating the list box at runtime, your idea of calling a controller action to get the new items is sound; I'm not familiar with ASP.NET, so I can't really help you there.
The ID of the <select> that TinyMCE creates takes the form editorId_controlId, where in your case controlId is "mylistbox". Firebug in Firefox is the easiest way to find the ID of the <select> :)
Here's the test button I added to my page to check if the above code was working:
<script type="text/javascript">
function doFoo() {
// Change "myEditor" below to the ID of your TinyMCE instance.
var insertsElem = document.getElementById("myEditor_mylistbox");
insertsElem.options.length = 1; // Remove all but the first option.
var optElem = document.createElement("option");
optElem.value = "1";
optElem.text = "Foo";
insertsElem.add(optElem, null);
optElem = document.createElement("option");
optElem.value = "2";
optElem.text = "Bar";
insertsElem.add(optElem, null);
}
</script>
<button onclick="doFoo();">FOO</button>
Hope this helps, or at least gets you started.
Step 1 - Provide a JsonResult in your controller
public JsonResult GetInserts(int containerId)
{
//some code to get list of inserts here
List<string> somedata = doSomeStuff();
return Json(somedata);
}
Step 2 - Create javascript function to get Json results
function getInserts() {
var params = {};
params.containerId = $("#184").val();
$.getJSON("GetInserts", params, updateInserts);
};
updateInserts = function(data) {
var insertsElem = document.getElementById("183_mylistbox");
insertsElem.options.length = 1; // Remove all but the first option.
var optElem = document.createElement("option");
for (var item in data) {
optElem = document.createElement("option");
optElem.value = item;
optElem.text = data[item];
try {
insertsElem.add(optElem, null); // standards compliant browsers
}
catch(ex) {
insertsElem.add(optElem, item+1); // IE only (second paramater is the items position in the list)
}
}
};
Step 3 - Create NativeListBox (code above provided by ZoogieZork above)
var mlb = cm.createListBox('mylistbox', {
title: 'Inserts'
}, tinymce.ui.NativeListBox);
// Set our own change handler.
mlb.onPostRender.add(function(t) {
tinymce.dom.Event.add(t.id, 'change', function(e) {
var v = e.target.options[e.target.selectedIndex].value;
tinyMCE.activeEditor.execCommand("mceInsertContent", false, v);
e.target.selectedIndex = 0;
});
});
//populate inserts on listbox create
getInserts();

Resources