I have a problem when using window.location.href. It works fine in IE9 and IE10. But when I test it in IE8, it redirects me to another page. It suppose to download a file. Please help me with this one. Thanks.
Here is my code:
ScriptManager.RegisterStartupScript(this, this.GetType(), "key:" + DateTime.Now.ToString(), "window.location.replace('Document.aspx?table=TV_IMAGES');", true);
I also tried using window.location, document.location, making it a function and using session time out. But none of these work.
You can just Use window.location = 'http://demo.org/#anchor';
Change up to your requirements..Hope this will Help you out
Try
Window.location.href= 'Document.aspx?table=TV_IMAGES'
instead of replace function
Related
i'm a rookie in laravel.
I have a page in admin profile (/Profile /admin). But if someone put
http:// ... / Profile/admin
. Happen a jump directly to the admin page without login.
I tried putting:
Route::filter ('/Profile/admin',function ()
{
if (Auth::guest ()) return Redirect::guest ('login');
});
but i dosen't work.
Thanks.
You can run filters on your routes to basically check to see if someone is logged in or not. There is probably a bit you need to do to make sure all is secure.
However, suggested reading:
http://laravel.com/docs/routing#route-filters
http://laravel.com/docs/security
Hope it helps.
I developed a webapplication with ajax.
its fine with firefox but under IE8 some of my ajax dynamics (e.g. changing a div after a button etc.) are not working. only if I disable the browser-cache (F12 - Cache - always reload from server).
think IE doesnt check that a ajax-response has changed a part of the site or something else.
any ideas i can handle this with this option on??
I tried random-numbers in the request or timestamps in the response but didnt work.
thanks!
ch
try with.
$.ajaxSetup({ cache: false });
Not sure what server side language you use... I used code below at the server side(in the ...aspx.cs file):
Response.AddHeader("Cache-Control", "No-Cache");
Response.Write...
I'm building a website with Facebook Connect and therefore using the Facebook Javascript SDK.
Problem: when using Firefox, the page doesn't reload properly once logged in or logged out.
FB.Event.subscribe(
'{% if current_user %}auth.logout{% else %}auth.login{% endif %}',
function(response){
window.location.reload();
});
Obviously, it looks like a known problem (just type "window location reload not working on firefox" and you'll get a lot of results)
More precisely, Firefox doesn't seem to send the right cookie when reloading the page...
- When I click to login, once Facebook logged me in and sets a cookie, Firefox doesn't send any cookie
- When I click to logout, once Facebook has logged me out and remove the cookie, Firefox sends the cookie that was previously there.
I conclude it uses some "cache functions".
I tried to make a workaround as described here and implemented this:
redirect_url = encodeURIComponent(window.location.href);
url = window.location.href + "account/login?redirect_url=" + redirect_url;
window.location.replace(url);
But the problem remains (the cache I guess...) Can you help me out with this?
Thanks.
Try wrapping the window.location.reload() call in a setTimeout() with a zero delay. Apparently, Firefox fires the event before setting the cookie. The wrapping should place the reload call in the event queue and allow the cookies to be set correctly.
Incase there was anymore confusion over this, for Firefox, the above referenced example of setTimeout() works perfectly. Simply include your reload call, or if it's easier just replace:
document.location.reload();
with:
setTimeout('document.location.reload()',0);
Using the most recent version of Firefox released, I have tested every example above, and this is the only one that has actually worked consistently. Basically, you just need to "pause" the JavaScript just for a moment to let the rest of the script catch up. I did not test this on Chrome or IE, but it does work flawlessly on Firefox.
We are using the work-around with
window.location.href = url;
instead of
window.location.replace(url);
Works fine in Firefox, too.
For anyone using Rails and Koala, you can just check for the cookies and redirect to the same action if they are not present:
def fb_authenticate
#fb_cookies ||= Koala::Facebook::OAuth.new.get_user_info_from_cookie(cookies)
if #fb_cookies
#login user or create new user
else
redirect_to :controller => 'account', :action => 'fb_authenticate'
end
end
Try redirect to a different URL each time:
top.location.href = 'https://apps.facebook.com/YOUR_APP_NAME/?t=' + <?php echo time(); ?>;
, I use PHP but you can replace with JS ( Math.round(+new Date()/1000) I guess ).
I am using jQuery form plugin to upload images in my MVC project.
For some reason the Code in IE no longer working (worked before):
I can tell the submit is successful, image is successful uploaded, and recoded in database, however the response seems somehow corrupted in IE.
function showResponse(responseText, statusText, xhr, $form) {
$("#loading").hide();
AddImage(responseText.ImageId);
buildArray();
}
I tested on Firefox, Chrome, Safari, it all working fine, however when i use it in IE.
I got error:
Message: 'ImageId' is null or not an
object
Anyone have had any similar problem before?
Thanks in advance!
Well the problem solved by changing the content type from "text/plain" to "text/html", that's it.
OMFG, Internet Explore!
Code I have changed:
return Json(newImage, "text/html", Encoding.Unicode, JsonRequestBehavior.AllowGet);
hope that would help someone else as well.
As said in the documentation about File Uploads:
It is important to note that even when the dataType option is set to 'script', and the server is actually responding with some javascript to a multipart form submission, the response's Content-Type header should be forced to text/html, otherwise Internet Explorer will prompt the user to download a "file".
I don't know it worked before, but the documentation is clear about this concern.
I want use $.ajax to read some infomation from xml file,here is my js code :
$.ajax({
type: "get",
url: "Database/App_all.xml",
dataType: "xml",
timeout: 2000,
beforeSend: function () {
},
success: function (xml) {
$(xml).find("app[id='id-1']").appendTo($("#contain"));
},
error: function () {
alert("ajax failed!");
}
});
However, the code only work great in firefox and opera.
It doesn't work in chrome(7.0.517.24 ) and safari(5.0.1),failed without any alert,not even the alert("ajax failed").
Is there any bug in $.ajax in chrome and safari?so how to solve the problem?
thank you very much:)
You should use chrome's or safari's built-in developer tools (ctrl+shift+i) to track JS errors and track actual AJAX requests.
Is your code wrapped in document.ready? Is there any erros in javascript console? Also try to output something after success callback line.
Another cause for this could be incorrect mime-type for your XML file returned by server. It should be [Content-type: text/xml]. You can check that in chrome's or safari's built-in developer tools - just look for headers tab when xml resource is selected. If it 's actual problem, you may need to tweak web-server configuration (main config or .htaccess for apache) to return correct mime-type.
First thank you gajendra.bang and Māris Kiseļovs give me your advices,I have konw what's wrong with my code,after I get a bad resault ,I trying to know what the $.ajax get from xml exactly,so I use firebug check the div#contain I found that:
<div id="contain">
<auther>cocept</auther>
</div>
yes,I think the <auther></auther> must the problem,I don't even konw the $.ajax would get the tagname as well
so I rewrite it :
success: function (xml) {
$("#contain").html($(xml).find("app[id='id-1']").find("auther").text());
}
then the div$contain is:
<div id="contain">
cocept
</div>
so ,the chrome and safari could show again!
I suppose you have problem with reading of the local file per ajax. Ajax can be used to read a file from the same web server, but there are some security restriction if you read it not per HTTP.
In firefox and opera you can read local files (with url like file:///C:/Program%20Files/My/Database/App_all.xml) per ajax without any problem.
In Internet Explorer you should use dataType: 'text' and then convert the text to XML (read more here).
To be able to read local files in Chrome you have to restart chrome with another parameters:
chrome.exe --allow-file-access-from-files
(Be sure that all other instances of chorme closed before starting Chrome.exe in the way).
This is a problem for local files... You should try uploading them on a web server and check from there
$(xml).find("app[id='id-1']").appendTo($("#contain"));
what is xml basically returning, an element with "#" like "#mydiv" or class like ".mydiv"
I think you are trying to access an element and if you are not returning it with "#", try
$("#"+xml).find("app[id='id-1']").appendTo($("#contain"));