MVC IE9 Issue - breakpoints in view not being hit - asp.net-mvc

I have a weird problem on my site that only happens in IE9 - I have some js code that I need to add to the page but only for IE9 as it is to sort out the placeholders. However the code is not getting added and I don't know if this is a bug with IE9 or MVC.
The problem is that I put the code for the script at the top of the view - it gets added to a session which then gets rendered on the master template, but in IE9, the view is not being hit so the code doesn't get rendered. I have put a breakpoint onto the view and visited the page in all the browsers. The breakpoint gets hit and then moves onto the master layout in every browser except IE9 where the breakpoint is completely missed (no matter where I put it in the view) and the master layout is loaded first.
However if I do a postback on this page, the view will then be hit and the script will render.
Has anyone had this problem before or know what causes it
Update
the code in the controller isn't hit in IE9 either. Is this a caching problem - if so, how do I stop MVC caching a page
Okay, a further update is in IE9, I have noticed that the url being loaded is http://localhost/Quote/#/Quote/Form/ but in every other browser the url is the correct one: http://localhost/Quote/Form/. If I go to the correct url then the page works properly in IE9.
Is this caused by jQuery mobile ajax enabled option?

The error was caused by the # being added to the url. I found that if I entered the following code just before the jQuery mobile script:
<script type="text/javascript">
$(document).on("mobileinit", function () {
$.mobile.ajaxEnabled = #Html.Raw(Request.Browser.IsMobileDevice ? "true" : "false");
});
</script>
It solved my problem

Related

Remove disable page with fixed hedaer in jquery mobile

I developed a project in jquery mobile which have fixed header. its working fine in laptop browser but when I run in mobile browser then after browse some pages my mobile getting stuck because jquery mobile keep cache of previous page. so to remove previous pages I added below code
$(document).on( "pageshow", function( event, data ){
$('div[data-role=page]:hidden').remove();
});
It also worked fine but now when i clicked on a link first time it remove previous page data as well padding-top from ui-page which was added for fixed header. now if I goes to next page and again comes on this page its work fine.
Please suggest, Thanks!!!

Debugging on-launch Javascript in UIWebView

I'm currently debugging a webpage which is embedded in a UIWebView for display in the app.
It uses some elaborate on-load Javascript which works fine in the Android app but breaks in the iOS app.
This answer pointed me to Safari Web Inspector for UIWebView - however, since the broken Javascript is being run on page load, I can't actually attach the inspector in time to capture whatever's going wrong.
Right now I'm hacking around it by manually inserting a delay into the page, but is there a better way (one that doesn't require I make changes to the page code itself, start the app, rush to load it up in Safari, then wait a while longer for it to continue)?
Important edit: in Safari 7.0, you can reload the page by selecting the "Resources" view, and clicking the refresh arrow next to the top-level page. [It seems you can also do it in at least some versions of Safari 6 by selecting the document tab, clicking the top-level page to select it, and pressing Command+R (the same shortcut used to refresh the page in normal Safari).] Breakpoints you set will still exist if you refresh the page from the Safari Web Inspector, because doing so does not cause SWI to detach the way reloading the page from within your app or the Xcode debugger does. This means that as long as the page doesn't do a Javascript redirect or trigger side-effects in the app itself, you can step through the onload Javascript by loading the page once, setting your breakpoint there, and then reloading the page from within SWI.
Original post: The only solution I was able to find was putting in an "extra" call to shouldStartLoadWithRequest: as follows:
Add a script (not onload, synchronous) as the first element in the page head:
<script type="text/javascript">
window.location = "myapp://catchme";
</script>
Set an XCode breakpoint in shouldStartLoadWithRequest:
Edit the breakpoint to set a condition of:
(bool)[[[request URL] absoluteString] isEqualToString:#"myapp://catchme"]
(Without this condition it will stop on the initial shouldStartLoadWithRequest: call, which isn't what you want because the page won't yet be available to attach the Mobile Web Inspector to at this stage.)
Start the page load, and when it hits the (Xcode) breakpoint, switch to Safari, and launch Mobile Web Inspector with Develop > iPhone Simulator > (my page), then switch back to Xcode and resume execution within a short window before all the resource requests on the page time out.
Weinre helped me to solve this issue, since it's connected right from the start, you get full control of the page.
Why not putting a breakpoint in shouldStartLoadWithRequest and then open the inspector?
Not 100% related to the question OP asked, but I had a similar problem with an Android WebView, in a mobile app whose native code I do not control (but which has WebView debugging enabled).
document.reload() and all other similar means of reloading the page were not working for me
I was thinking to put alert() at the very top of the page, which in theory is a blocking call, but it was not working for me either.
Finally, I went with a blocking, synchronous XHR.
In order to inject an artificial delay when the page is loading, I added a fake call to an endpoint under my control that returns 200 OK after 15 seconds.
Put this at the very top of the <head>
<script>
try {
var request = new XMLHttpRequest();
request.open('GET', 'https://whatever/please-freeze', false); // false = sync XHR
request.send(null);
} catch (err){
debugger;
};
debugger;
</script>
You can for example create your own simple http server with an endpoint behaving like this, but this is a bit of an overkill.
The debugger statements didn't trigger breakpoints in Chrome for whatever reason, but the manually defined breakpoints in the dynamically loaded code (created before) worked fine.
A hack for Windows (Fiddler) users
Since I'm on Windows, I used Fiddler to create an autoresponder with latency.
I also used Fiddler to edit the HTML of the original page request, to inject the <script> mentioned earlier.

jQuery Mobile on Android: page load

I have a web application that runs just fine on Android until I started to use jQM. It still runs fine with jQM on the desktop...
The problem is that when I load a "new URL" using "window.location.href = newLocation;" the new page loads fine the first time but the next time the page is displayed ok but then disappears and I can just see the header and footer of the first page (not the second). When I refresh I see the second page ok. Another way to have it working is to always refresh the first page b4 launching the second.
I have tried to disable page transition and Ajax but with no success.
If I run (I guess it is stupid):
$.mobile.changePage(newLocation, { transition: "none"});
window.location.href = newLocation;
it always works but then I sometimes get "Error loading page".
Any ideas? $.mobile.changePage(newLocation, { transition: "none"}); alone does not work...
Here is a "bypass" solution. It works but there may be better ones...
First I tried to add some JS to force a reload of the first page when coming back from the second but no JS executed...
Then I saw After travelling back in Firefox history, JavaScript won't run and just added "window.onunload = function(){};" to the first page. This prevents caching of the first page and now things are working.
It looks like page caching was causing the problem but I don't know why this means that jQM fails...

Page refresh (F5) in JQM native app clear's the dom -> no styles and scripts loaded

I have one larger .js file loaded in the head of the app. entry point (index.html) instead of loading page-specific scripts inside their data-role="page" div.
So i have all the page specific scripting in one js that is loaded once from the index.html which always remains in the DOM.
So for example i have handlers like:
$(document).on('pageshow', '#page_Albums', function()
{
// code for the albums.html page
});
..etc
This is my problem:
When you start navigating the app everything is okey until you hit f5 or browsers refresh button.
This so called full-refresh won't load my central js file, also the needed jquery-mobile resources from the head of index.html (js & css) are lost.
Due to this it's obvious where the problem lies. When i hit refresh from index.html then everything works fine.
How to fix this?
thx
On the navigation links try use data-ajax="false" it will re-command your js...
For example,
<a href="#xyz" data-ajax="false>Link</a>

Embedded video not rendering in Chrome on first load after embed code is saved to a Rails model

We have an Ruby on Rail app that allows the user to save a number of video embed codes into a into our data model. The form allows the user to enter any number of embed codes, press submit and save everything to the database. The app then redirects the user to a page that has a list of all the embed codes.
This workflow works fine for IE, Safari, and Firefox.
On Chrome, however, the first time the page is loaded none of the videos appear on the page. I see the following error in the console, once for each video:
Refused to execute a JavaScript script. Source code of script found within request.
On subsequent page loads, the videos load fine and that error is not displayed.
When I view source, the page is reloaded for the view-source operation so I cannot tell if the source is coming through as expected.
When I inspect element on the block where the video should be, I see the following:
<iframe src="" width="400" height="225" frameborder="0">
<html>
<head></head>
<body></body>
</html>
</iframe>
This occurs for both the iframe style embed codes as well as for the "old-style" tag code for both YoutTube and Vimeo videos.
Related:
Refused to execute a JavaScript script. Source code of script found within request
It's how Chrome prevents XSS (cross-site scripting), as your reference above.
When you submit your embed codes, and redirect to another page to display them, Chrome sees that the submitted embed codes (via HTTP POST))and the responded embed codes are the same, so it prevents to load them and displays error in the console.
When you refresh the page, no more HTTP POST submitted (because you redirected it before), so it should display correctly.
I have same problem, and I resolved it by auto reloading the page after it redirected.
I reload the iframes via javascript (with jquery) as workarround..
I therefore store the src elsewhere cause chrome removes it..
I added the url twice as src and src2, and reloaded then with src2.
I also gave all the iframes that need reloading a special class 'webkitIframeHack'.
<script type="text/javascript">
$(function(){
if ($.browser.webkit) {
$("iframe.webkitIframeHack").each(function(){
$(this).attr('src', $(this).attr('src2'));
});
};
});
</script>
(I can't use html5 data-* attributes, i think they would be more fitted..)

Resources