Turn off JavaScript notifications in IE9 and FireFox4 - javascript

In web development, JavaScript is often executed when clicking on elements.
In both Internet Explorer 9 and FireFox 4 a little message pops up in the bottom left hand corner with the JavaScript function will be executed by clicking on elements these elements.
ASP.NET makes use of the JavaScript __doPostback(...ugly parameter names..) on almost every element that sends a request to the server. This JavaScript is automatically added to the HTML elements that are generated by the ASP.NET controls and I have no way to circumvent this.
For example, an ASP.NET DropDownList is rendered as an HTML Select element and the __doPostBack() method is added to it so that whenever the user selects a new element, the server can process this action.
The __doPostaback() method is embedded into many of the ASP.NET controls and there is no easy way to change this.
One of my end users commented that this new feature makes it feel as if they are in "Debug-mode"....
So, my question is: how do I either make this popup show something user friendly...or is there a way to tell the browser (via HTML) not to display this nastiness?
Thanks!
-Frinny

Why don't you make the href of the link a hashtag and attach the actual action via JavaScript:
HTML
<a id="foo" href="#foo">Foo</a>
JS
var foo = document.getElementById('foo');
foo.onclick = function(e){
//script foo!
return false;
};
Your location will still be #foo to look nice, but the actual action will be in the foo.onclick function.
Alternatively you can specify the event inline (Foo), but I try to keep a clear MVC separation with HTML, CSS, & JS.
Using a hashtag also gives you the ability to listen for hash-change events or check the hash tag onload so that a user can still middle-click a link and have it work correctly in a new tab.

To my knowledge there isn't a way to make it not display, as that is part of the browser and not the page.
What I would do is create javascript functions at the top of the page with user readable names that contain the other functions inside.

Related

Trigger some JavaScript function with selenium on a webpage to load new elements

I'm trying to get some data from a webpage:
https://www.cabotcorp.com/solutions#product-index
On this webpage, whenever you scroll down to the end, it takes a couple of seconds and then loads a new set of items.
When that happens something gets added to the HTML which I want to look at with selenium in python.
So my question is pretty general:
Is there a way to force the function that loads the new elements?
My first idea is as follows:
driver.execute_script("arguments[0].scrollIntoView();", driver.find_element(By.CLASS_NAME, "some class at the bottom of the page"))
This is the code I would use to let selenium scroll down to some element on the webpage. After that I would just sleep for a set amount of time to assure that the new elements loaded in.
However, I noticed that this webpage uses "ddscrollspy"
https://github.com/dynamicdriverepo/ddscrollspy
Is there a way to use selenium to trigger a new set of items?
I'm basically looking for a function that triggers certain Javascripts that are available on a certain webpage.
Edit:
A friend suggested looking for triggers:
This is what I found in Chrome:
So I now have access to the code that gets executed whenever something new loads. Now I just need to know how to trigger that code on demand.
Thanks for the help.

How to pass values from HTML webresource to javascript on window close MSCRM

I am opening HTML webresource using Xrm.Navigation.openWebResource but on closing of HTML window I want to pass values from HTML to javascript file from where it is opened. Is there call back function can be implemented?
If I open HTML window using window.open I can call parent javascript function using window.opener.functionname on close but click but I want to know how I can pass values to parent javascript file on close button click of HTML window.
I tried with window.parent.opener.Functionname() but it is not working - getting functionname is undefined but it is defined in parent javascript. Pls suggest.
If you're using the 'old' (as it not the unified interface) user interface with turboforms enabled then the parents javascript is actually in a extra iframe called customScriptFrame, and not on the parent itself.
To call something on the parent you can use
parent.customScriptsFrame.functionname() for IE
and
parent.customScriptsFrame.contentWindow.functionname() on chrome.
On the unified interface its much the same, but far more troublesome.
Now the scripts are in a iframe called ClientApiFrame_[n] where [n] is some random number. And i haven't found a good way to determin that number ahead of time from a webresource.
You could go over all frames of the parent in javascript (parent.frames) to find one that has a id that starts with ClientApiFrame_ but that will throw errors trying to read frames with sources set to external domains, and i dont think is very good practice.
Another possibility is registering the function you want to call with the parent ahead of time. so in the main javascript use this.
parent.functionname = functionname
And then from the webResource you can use the normal
parent.functionname
If the webresource is embedded in the form, then use window.parent
If you Xrm.Navigation.openWebResource to open it, then use window.opener

Get all jQuery/JavaScript event subscriptions of element

all forms on my website are getting submitted by AJAX. And I can't find where it is implemented.
When I look into HTML I see the plain <form> with submit button, but form is always sent asynchronously.
I know that some .js file contains something like this:
$("form").onsubmit(function(e) {
var form = $(this).serialize();
$.post(......
e.preventDefault();
.....
});
But I cant find this code. My JavaScript doesn't do such things.
Where I can get the event subscriptions for events of particular element (or all form elements)?
Thank you
UPD:
Ok. It seems I found the suspect. When I remove script reference to jquery.mobile my forms are sending normally.
How to disable sending by AJAX for one particular form?
You can download chrome, select an element. Then at the right side of your developer tools (Where you also have css). There is a tab called "Event listeners". You can see all events bound to the element here - and their location (file + line number). Note that you need to check parents aswell, as events bubble up the dom tree.
If you are a firefox user, You can use firebug to see the events.
You can also see the events by using the below code. But this will not tell you which script and line.
$('selector').data('events');
Like this on this page:
$('#show-editor-button input').data('events')

WebForm_AutoFocus is not being generated

I have an ASP.NET page which sometimes does not generate the expected "WebForm_AutoFocus()" javascript, even though I am explicitly calling .Focus() on one of the controls. Are there any known scenarios where some factor would prevent that javascript from being generated?
Specifically, when the user clicks a particular button, I'm creating some new controls dynamically: in this case a text box. In OnPreRender I'm grabbing that newly-created control and calling .Focus() on it. The idea is, when the postback completes, the browser gives focus to the newly-created textbox control. However, the generated HTML (verified via firebug and fiddler) simply does not contain a WebForm_Autofocus call at all.
In other scernarios, the same page (on postback or on initial hit) calls .Focus() on a different control - one which is not dynamically created; in those cases the WebForm_AutoFocus() script is generated perfectly, and all is well.
Unfortunately, I'm working on a client system that LOVES frameworks upon frameworks, and abstractions upon abstractions, so I cannot post a meaningful/concise code sample here. However, if any of my friendly SO'ers knows more about generation of that "WebForm_AutoFocus" javascript - and scenarios which would prevent it from being generated - that would give me a good place to start digging.
The autofocus call only gets included if asp.net thinks there is a need for it. Set a default button on the page so that asp.net will know to make the method.

ASP.NET __doPostBack rendered after beginning or near end of form tag

I'm trying to manually call the ASP.NET (3.5) javascript postback function __doPostBack from my javascript code. The problem is that the postback script block, that is normally rendered right after the beginning of the <form> tag (and the hidden fields), is occasionally rendered near the closing </form> tag.
Is there any way to force it to be rendered near the beginning of the form tag? Also, how does ASP.NET decide when/where to render the postback client script block?
Edit > Additional Info:
The javascript code resides inside a user control that references the __doPostBack function. The control itself does not contain any 'postback controls' that would call that function. (When I mention 'postback controls', I mean ASP.net controls that call the __doPostBack function and not the asp.net ImageButton and Button controls)
Based on what I've observed and #Brian's comment on the dependency of the postback script on the availability of 'postback controls' on the page, I've found that when the page contains controls that cause postback, the __doPostBack script block is rendered after the opening <form> tag and when there are none, it renders them near the closing </form> tag (or according to this it's not even supposed to be rendered). Now it would make sense for ASP.NET not to render the postback script if there are no controls that require it, but the apparent position of the script near the closing tag is the one that still eludes me. I haven't been able to find any documentation that suggests this behavior. All I've been able to find was this.
Having said that, I've found a couple ways around this issue:
Add a 'postback control' and set its visibility to hidden via css (not the Visible property). eg. <asp:LinkButton ID="RequirePostBackScriptLink" runat="server" style="display:none;" /> (this is what I'm using)
Add the control to the Page.RegisterRequiresPostBack and implement the IPostBackDataHandler interface.
Finally, as #Jonathan_Bates mentioned in his post, the proper thing to do is to wrap the reference to __doPostBack inside a function that is an event handler to load (or ready if you're using jquery). That way, there wouldn't be a need to depend on the actual placement of the __doPostBack script.
It'd be great if anyone can provide more info on this, aforementioned, behavior.
I am guessing that where it renders is important to you so that your scripts render after it and can invoke it (which let me say up front, is a bad idea to begin with).
You just need to make sure that whatever script you are using to call __doPostBack calls it after its been read into the browser. If you use a library like jQuery and its $(document).ready() convention, you can be sure that your code won't execute until all other code is loaded, and therefor your code would be able to call __doPostBack.
Some of it is controlled by the controls that render, whereas the page injects the client script blocks and startup scripts at a pre-defined point...
I assume this is for a control or something? This isn't for a standard block?

Categories