3
Answers

javascript script code doesn't work on c# webbrowser control

Photo of shlomi gadol

shlomi gadol

9y
8.1k
1
Hi,
I took from tradingview site this widget script and put it on my webbrowser control but it doesn't show nothing. This is the code from the site:
 
<!-- TradingView Widget BEGIN -->
<script type="text/javascript" src="https://d33t3vvu2t2yu5.cloudfront.net/tv.js"></script>
<script type="text/javascript">
new TradingView.widget({
"autosize": true,
"symbol": "AMEX:SPY",
"interval": "5",
"timezone": "exchange",
"theme": "Black",
"style": "1",
"toolbar_bg": "#f2f2f2",
"withdateranges": true,
"hide_side_toolbar": false,
"allow_symbol_change": true,
"hideideas": true,
"show_popup_button": true,
"popup_width": "1400",
"popup_height": "900"
});
</script>
<!-- TradingView Widget END -->
 
and this is what I wrote:
 
webBrowser3.AllowWebBrowserDrop = false;
webBrowser3.IsWebBrowserContextMenuEnabled = false;
webBrowser3.WebBrowserShortcutsEnabled = false;
webBrowser3.ObjectForScripting = this;
 
webBrowser3.DocumentText =
"<html><body><script type='text/javascript' src='https://d33t3vvu2t2yu5.cloudfront.net/tv.js' ></script>"+
"<script type='text/javascript' >"+
"new TradingView.widget({" +
" 'autosize': true," +
" 'symbol': 'AMEX:SPY'," +
" 'interval': '5'," +
" 'timezone': 'exchange'," +
" 'theme': 'Black'," +
" 'style': '1'," +
" 'toolbar_bg': '#f2f2f2'," +
" 'withdateranges': true," +
" 'hide_side_toolbar': false," +
" 'allow_symbol_change': true," +
" 'hideideas': true," +
" 'show_popup_button': true," +
" 'popup_width': '1400'," +
" 'popup_height': '900' });" +
"</script></body></html>";
 
If someone can help, it would be great
 
Thanks a lot
Shlomi

Answers (3)

0
Photo of Ryan Alford
NA 2.3k 891.7k 16y
Instead of using the "Browse" tab, use the "Project" tab to add a reference.
0
Photo of Stefan
NA 624 0 16y
You don't have to have both in the solution explorer. Open the main project you will be using. In the solution explorer, right-click the references folder. Click "Add Reference...". In the pop up, select the browse tab. Browse the project folder of the project you want to call from. Go to the debug folder and select the .exe or .dll of your project. Select "OK". You should now see the name of that project in your references folder. Add it to your namespaces (i.e. "using MyProject"). Now simply call the method the way you normally would (i.e. "MyProject.Class1.Method1();").

Alternatively, Visual Studio has an option to add a project to your current solution.

Hope this helps!