WebBrowser Control in Silverlight 5 xaml view issues using some javascript - javascript

I have an OOB silverlight application. I have Silverlight 5 developer runtime and all the silverlight 5 developer tools installed. The OOB Application has a silverlight view with a WebBrowser control on it. The Source that of webBrowser control is this aspx page:
<head>
<title></title>
<script type="text/javascript" language="javascript">
function test() {
if (hiddenDiv.style.display == "none")
hiddenDiv.style.display = "block";
else
hiddenDiv.style.display = "none";
}
function handCursor() {
clickTest.style.cursor = "hand";
}
function defaultCursor() {
clickTest.style.cursor = "default";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<%--This Link Doesn't Work--%>
Javascript Href test</br>
<%--This Link Works--%>
<a id="clickTest" onclick="test()" onmouseover="handCursor()" onmouseout="defaultCursor()" style="text-decoration: underline; color:Blue">OnClick Test</a>
<div id="hiddenDiv" style="display:none; background-color:Black">
<span style="color:White; display:inherit">Look at me!</span>
</div>
</div>
</form></body>
(Note: Yes I know the above code is not complete HTML. I could not get the editor to display the full page properly. I cut off the html tags. Also note that this is just a test page, not the real page I want to display in my app. I was just trying to isolate the problem).
When the above code is run in IE9 it works just fine. The links make the Div called "hiddenDiv" hide and show. When it is displayed in a WebBrowser control in a silverlight app it works fine on another developer's machine, but on my machine it does not. I click the link and nothing happens. It appears that the javascript simply does not execute. It appears to only have this issue using the href=javascript method. onclick works great. Unfortunately I don't own the pages i want to display in my app and cannot change the code.
A co-worker of mine believes that this issue might be due to my mistakenly installing the standard silverlight 5 runtime before realizing my mistake and installing the developer runtime. Even though I have since removed the offending file and reinstalled the Silverlight5 Tools.exe. In fact I uninstalled and re-installed all silverlight related products (except VS 2010) and uninstalled IE 9. All to no avail.
If anyone has any additional information on this problem please let me know. We need a solution that does not involve modifying the html. I dont control that html. I am hoping to embed an external web application in my OOB SL application by simply displaying it in a web browser control inside my application.

I discovered the answer to this issue on this thread:
FEATURE_SCRIPTURL_MITIGATION
The issue is a registry setting that turns elements of javascript execution on and off. It is also described in this MSDN Article:

Related

Alert does not trigger, JS is not detected

I think I might be going crazy at this point. I had an ASP page working yesterday, and came in today to Firebug telling me it cannot detect the JavaScript on the page. Love it when things change after not touching them.
So I start trying to figure out what is happening. I tried slimming down the code, this answer, restarting Firefox, saving the page under a new name and loading the new one, and adding a ridiculous amount of code I generally consider unnecessary. I even tried removing everything from the page and changing it to this:
<script>
alert("yay");
</script>
Does not trigger alert, and Firebug says "No JavaScript on this page". I've been looking for explanations for almost 2 hours and cannot figure out what is happening. I know I did not deactivate anything because other pages will show JavaScript and function properly. I also know that no add-ons are causing it.
I am using Firefox 28.0 (also tried on 27.0.1). Opening the page in Chrome triggers the alert.
(Damn I meant to post this as a comment).
As you responded I'll re-popualate...
I create jsfiddle,
<body>
<script>
alert("yay");
</script>
</body>
Also ensure your browser has javascript enabled.
You should follow the instructions on the Firebug's first aid page.
I assume it's either some Firebug setting or a conflict with another extension. (I see at least YSlow and FlashFirebug installed.)
To check that you can create a new profile and just install Firebug.
Closing the tab and opening the same link in a new tab seemed to resolve the issue.
I'm not sure if any of the prior attempts factored in, so I will list them as well. To be clear, none of these worked, but may have paved the way in some fashion.
Restarting Firefox
"Clear Activation List" on Firebug
Save page under new filename and load the new page
Uninstalling add-ons (all of them)
Create new profile and load page on that profile
Add a <!DOCTYPE html> to the top
Add type="text/javascript" to script tags
Add charset="utf-8" to script tags
Add <meta charset="utf-8"> in <head>

Open a local HTML file in Full screen in IE without showing a security prompt

We have developed an offline HTML application - basically a collection of HTML pages with some JS and CSS resources (external files that are referenced in HTML page) to support it.
To run this app, all the client (customer) needs to do is to just open the "LandingPage.html" file in his IE Browser (client will only be using IE).
Recently the client asked for the application to be designed such that it automatically opens in full screen mode. So they don't want to be asked to press F11.
We implemented this using the many different JavaScript solutions available - but all of them use ActiveX / cause the security prompt to appear which the user has to acknowledge.
We cannot recommend the user to go and change the IE Security settings related to Active X Objects / Scripts / Initialization etc - that suggestion isn't well received.
The client wants the application to open in full screen -
Without showing any prompt / asking for acknowledgement
It should be automatic / it should not require user to press F11 or any other button.
They don't want the page to be opened in another window (we demo-ed the window.open solution too ... ) either.
Any suggestions to achieve this functionality? I know there are too many constraints ...
You may use a Launcher for the IE (may be some script or a HTA-file as well)
Example-HTA:
<html>
<head>
<hta:application
showintaskbar="no"
singleinstance="yes"
sysmenu="no"
windowstate="minimize"
>
<script>
IE = new ActiveXObject("InternetExplorer.Application") ;
IE.Visible = 1 ;
IE.navigate( "file://C:/path/to/LandingPage.html" ) ;
IE.TheaterMode=true;
//close HTA
self.close();
</script>
</head>
<body></body>
</html>
When you want to use it as script copy the first 4 lines of the <script/> into a file with the ending .js

JavaScript function not working on front page?

I have a modal window for the contact form with a link on the sidebar of my site:
<strong>Click to contact us</strong>
While it works perfectly on every other pages, it doesn't work on the home page. Try clicking it and it won't open the modal window.
The function openDialog() is defined in global.js:
function openDialog() {
jQuery("a#inline").trigger('click')
}
I don't know why. And I don't know how to debug JavaScript. It has no errors displayed whatsoever. Can you help me debug this and also let me know how I can debug it myself in future?
Thanks!
Suppose that you are using a kind of wordpress plugin named like "modal dialog". It seems like this plugin not well install on your home page but other pages, so check the plugin setup of all the layouts include the one used by home page.
<a id="contactLink" href="/contact-us/" style="color:#e40" > <strong> Click to contact us </strong> </a>
Inside your script file:
var contactlink = document.getElementById('contactLink')
contactLink.onclick = openDialog;
Would be a lot easier to debug if you didn't have CSS & Javascript mixed in with your markup. Separating everything (at least during production) is a good practice.
Get the Firebug Addon for FireFox. That's a good tool for debugging javascript. Also, you can hit F12 in your browser and the native development tools will come up.

How can i create webpage with out address/menu and tool bar

How can i create web page with out address/menu and tool bar.
I want the page to load without address/menu and tool bar.
Can someone please help to create webpage in asp.net or html using javascript.
I tried using javascript by using following code, but this warns that this page is closing i dont warning to be display.
a.htm
<head>
<script type="text/javascript">
function init()
{
var window_dimensions = "toolbars=no,menubar=no,location=no,scrollbars=yes,resizable=yes,status=yes";
window.opener=self;
window.close();
window.open("b.htm","_blank", window_dimensions);
window.moveTo(0,0);
window.resizeTo(screen.width,screen.height-100);
}
</script>
</head>
<body onload="init()">
These are standard security restrictions today, put there for good reason. Don't try to work-around them. If you think you have a need to do so, I'd re-review your requirements and reasons for doing so. If it is truly a need, you may need to consider a custom desktop (non-web-browser) application. This could still be a HTML-based application, but a custom desktop "browser" would be required.
See also: How to pop out a Firefox window without an address bar or status? (This includes excellent details for a custom desktop "browser", and follows the above recommendation.)

How to set breakpoints in inline Javascript in Google Chrome?

When I open Developer Tools in Google Chrome, I see all kinds of features like Profiles, Timelines, and Audits, but basic functionality like being able to set breakpoints both in js files and within html and javascript code is missing! I tried to use the javascript console, which itself is buggy - for example, once it encounters a JS error, I cannot get out of it unless I refresh the whole page. Can someone help?
Are you talking about code within <script> tags, or in the HTML tag attributes, like this?
Click
Either way, the debugger keyword like this will work:
Click
N.B. Chrome won't pause at debuggers if the dev tools are not open.
You can also set property breakpoints in JS files and <script> tags:
Click the Sources tab
Click the Show Navigator icon and select the a file
Double-click the a line number in the left-hand margin. A corresponding row is added to the Breakpoints panel (4).
Use the sources tab, you can set breakpoints in JavaScript there. In the directory tree underneath it (with the up and down arrow in it), you can select the file you want to debug. You can get out of an error by pressing resume on the right-hand side of the same tab.
You also can give a name to your script:
<script>
... (your code here)
//# sourceURL=somename.js
</script>
ofcourse replace "somename" by some name ;) and then you will see it in the chrome debugger at "Sources > top > (no domain) > somename.js" as a normal script and you will be able to debug it like other scripts
Refresh the page containing the script whilst the developer tools are open on the scripts tab. This will add a (program) entry in the file list which shows the html of the page including the script. From here you can add breakpoints.
Another intuitive simple trick to debug especially script inside html returned by ajax, is to temporary put console.log("test") inside the script.
Once you have fired the event, open up the console tab inside the developer tools.
you will see the source file link shown up at the right side of the "test" debug print statement. just click on the source (something like VM4xxx) and you can now set the break point.
P.S.: besides, you can consider to put "debugger" statement if you are using chrome, like what is being suggested by #Matt Ball
My situation and what I did to fix it:
I have a javascript file included on an HTML page as follows:
Page Name: test.html
<!DOCTYPE html>
<html>
<head>
<script src="scripts/common.js"></script>
<title>Test debugging JS in Chrome</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>
<script type="text/javascript">
document.write("something");
</script>
</div>
</body>
</html>
Now entering the Javascript Debugger in Chrome, I click the Scripts Tab, and drop down the list as shown above. I can clearly see scripts/common.js however I could NOT see the current html page test.html in the drop down, therefore I could not debug the embedded javascript:
<script type="text/javascript">
document.write("something");
</script>
That was perplexing. However, when I removed the obsolete type="text/javascript" from the embedded script:
<script>
document.write("something");
</script>
..and refreshed / reloaded the page, voila, it appeared in the drop down list, and all was well again.
I hope this is helpful to anyone who is having issues debugging embedded javascript on an html page.
I was having the same problem too, how to debug JavaScript that is inside <script> tags. But then I found it under the Sources tab, called "(index)", with parenthesis. Click the line number to set breakpoints.
This is Chrome 71.
Adding debugger; on top at my script worked for me.
I know the Q is not about Firefox but I did not want to add a copy of this question to just answer it myself.
For Firefox you need to add debugger; to be able to do what #matt-ball suggested for the script tag.
So on your code, you add debugger above the line you want to debug and then you can add breakpoints. If you just set the breakpoints on the browser it won't stop.
If this is not the place to add a Firefox answer given that the question is about Chrome. Don't :( minus the answer just let me know where I should post it and I'll happily move the post. :)
If you cannot see the "Scripts" tab, make sure you are launching Chrome with the right arguments. I had this problem when I launched Chrome for debugging server-side JavaScript with the argument --remote-shell-port=9222. I have no problem if I launch Chrome with no argument.
I came across this issue, however my inline function was withing an angularJS view. Therefore on the load i could not access the inline script to add the debug, as only the index.html was available in the sources tab of the debugger.
This meant that when i was opening the particular view with my inline (had no choice on this) it was not accessible.
The onlly way i was able to hit it was to put an erroneous function or call inside the inline JS function.
My solution included :
function doMyInline(data) {
//Throw my undefined error here.
$("select.Sel").debug();
//This is the real onclick i was passing to
angular.element(document.getElementById(data.id)).scope().doblablabla(data.id);
}
This mean when i clicked on my button, i was then prompted in the chrome consolse.
Uncaught TypeError: undefined is not a function
The important thing here was the source of this : VM5658:6 clicking on this allowed me to step through the inline and hold the break point there for later..
Extremely convoluted way of reaching it.. But it worked and might prove useful for when dealing with Single page apps which dynamically load your views.
The VM[n] has no significant value, and the n on equates to the script ID. This info can be found here : Chrome "[VM]"
Using Visual Studio (2012) I had the same issue and switching to IIS Express solved the problem!
The script tag's type attribute did not factor into it.
For some reason the Visual Studio Development Server does not provide everything Chrome needs to enable the breakpoints.
This is an extension of Rian Schmits' answer above. In my case, I had HTML code embedded in my JavaScript code and I couldn't see anything other than the HTML code. Maybe Chrome Debugging has changed over the years but right-clicking the Sources/Sources tab presented me with Add folder to workspace. I was able to add my entire project, which gave me access to all of my JavaScripts. You can find more detail in this link. I hope this helps somebody.
You have to add type="text/javascript" to the script blocks for them to be picked up as script. For example:
<script type="text/javascript"> ...your code here... </script>
for someone like me: just want to
(add breakpoint to) debug normal js code
<script> ... </script> inside/embedded html
Steps:
Sources -> Page -> Top -> find your html -> click -> right side show html and js script -> add breakpoint -> debug

Categories