Get IFrame's name from WebBrowser2 using VC++ COM - javascript

VARIANT varindex,varresult;
VariantInit(&varindex);
VariantInit(&varresult);
varindex.vt = VT_I4;
varresult.vt = VT_DISPATCH;
long lFrameNum = 0;
CComPtr<IHTMLFramesCollection2> pFramesCollection;
hr = m_spDoc->get_frames(&pFramesCollection); //CComPtr<IHTMLDocument2> m_spDoc
if(FAILED(hr))
{
return false;
}
hr = pFramesCollection->get_length(&lFrameNum);
if(FAILED(hr))
{
return false;
}
for(int i=0; i<lFrameNum; i++)
{
varindex.lVal = i;
if(pFramesCollection->item(&varindex, &varresult) == S_OK)
{
IDispatch *pDispatch;
pDispatch = varresult.pdispVal;
CComQIPtr< IHTMLFrameBase > spFrameBase(pDispatch);
if(!spFrameBase) return false; //failed here, E_NOINTERFACE
}
}
The codes here shows how to enum frames in a webpage, and get its name. I get the IDispatch of each iframe successfully, but when I tried to get IHTMLFrameBase (IID_IHTMLFrameBase), it failed with the error E_NOINTERFACE.
I am not familiar with COM, what did I do wrong? Help me please, thanks in advance.

Though, I didn't get the frame name directly, but I figured out how to get The IHTMLDocument2* of that specific frame. And Then, I can do something to the frame, like call its js functions etc. The codes are like below:
VARIANT varindex,varresult;
VariantInit(&varindex);
VariantInit(&varresult);
varindex.vt = VT_BSTR;
varindex.bstrVal = "Frame Name"; //the specific frame name
pFramesCollection->item(&varindex,&varresult);
IHTMLWindow2* pFrameWindow;
varresult.pdispVal->QueryInterface(IID_IHTMLWindow2, (void **)&pFrameWindow);
IHTMLDocument2* pDoc;
pFrameWindow->get_document(&pDoc);
//do something ...

Related

"jQuery requires a window with a document" on jquery $get

Why does this error happen when it try to use jquery? This code was working before but I don't even know what did I do for this error to happen. I tried to search about it and nothing I looked up makes sense or it's about this jsdom or whatever that I don't use. Exception is thrown on the 1st line in the try catch. That's the only error I could get from the browser debugger:
function DisplayName() {
if (Page_ClientValidate()) {
try {
$get("lblNameShow").html = $get("<%= txtNome.ClientID %>").value;
$get("lblDataAdmissaoShow").innerHTML = document.getElementById("datepicker").value;
var ddlD = document.getElementById("<%= ddlDepartamento.ClientID%>");
var strDDLDepart = ddlD.options[ddlD.selectedIndex].text;
$get("lblDepartamentoShow").innerHTML = strDDLDepart;
var ddlF = document.getElementById("<%= ddlFuncao.ClientID%>");
var strDDLFunc = ddlF.options[ddlF.selectedIndex].text;
$get("lblFuncaoShow").innerHTML = strDDLFunc;
//get valor radio button
var rstTel = $('#<%=rblTelemovel.ClientID %> input[type=radio]:checked').val();
if (rstTel == 0)
$get("lblTelemovelShow").innerHTML = "Não"
else
$get("lblTelemovelShow").innerHTML = "Sim"
var message = "";
var checkBoxList = document.getElementById("<%=cblAppAlternativas.ClientID%>");
var checkBoxes = checkBoxList.getElementsByTagName("INPUT");
for (var i = 0; i < checkBoxes.length; i++) {
if (checkBoxes[i].checked) {
var value = checkBoxes[i].value;
var text = checkBoxes[i].parentNode.getElementsByTagName("LABEL")[0].innerHTML;
message += value + "-" + text + ",";
}
}
//alert(message);
$get("lblAcessoShow").innerHTML = message;
$get("lblObShow").innerHTML = $get("<%= txtObservacoes.ClientID %>").value;
} catch (err) {
$get("demo").innerHTML = err.message;
}
$('#NewColabModal').modal('show')
}
return false;
}
EDIT
The code works if I remove the get from the jquery selector, but the strange thing is the code was working before. I can't find any info about using $get in jquery to select elements so I'm not sure about it if it's a plugin. This code was already implemented in the project I'm working on so I have no idea which plugin uses $get.
on the original project these are the only references on it
<link rel="stylesheet" type="text/css" href="jquery-ui-1.12.1.custom/jquery-ui.css" />
<script src="jquery-ui-1.12.1.custom/external/jquery/jquery.js"></script>
<script src="jquery-ui-1.12.1.custom/jquery-ui.js"></script>
<script type="text/javascript" src="NOTY/js/noty/packaged/jquery.noty.packaged.js"></script>
EDIT 2
So I was using a try catch to catch the error but I was doing it in the wrong way since I'm still new to javascript. The exception I got is that $get is not defined. So rather than asking where $get comes from, how do I define a variable in jquery like $get?

Javascript-Using Parsed Data From a Query String as a Heading

I am wondering how to take the information from a parsed query string and use it to display on the top of my page. Ignore the window.alert part of the code, I was just using that to verify that the function worked.
For example: If the user had choices of Spring, Summer, Winter, and Fall, whichever they chose would display a a header on the next page. So if (seasonArray[i]) = Fall, I want to transfer that information into the form and display it as a element. I'm sure this is easily done, but I can't figure it out. Thanks, in advance.
function seasonDisplay() {
var seasonVariable = location.search;
seasonVariable = seasonVariable.substring(1, seasonVariable.length);
while (seasonVariable.indexOf("+") != -1) {
seasonVariable = seasonVariable.replace("+", " ");
}
seasonVariable = unescape(seasonVariable);
var seasonArray = seasonVariable.split("&");
for (var i = 0; i < seasonArray.length; ++i) {
window.alert(seasonArray[i]);
}
if (window != top)
top.location.href = location.href
}
<h1 id="DynamicHeader"></h1>
Replace the alert line with:
document.getElementById("DynamicHeader").insertAdjacentHTML('beforeend',seasonArray[i]);

checking network connections using cordova

I'm trying to check my connections via cordova, the logic that I'm trying to do, is:
if network connected give "greetings" alert, else replace elements of the main view.
my difficult is to if connection ok, just give greetings message. someone could check my code to help me do to?
regards
function net(){
var theNet = navigator.connection.type;
var status = {};
status[Connection.NONE] = 'Sem acesso';
status[Connection.UNKNOWN] = 'Sem conexão';
status[Connection.WIFI] = 'Conexão wireless';
status[Connection.CELL] = 'Rede de operadora';
status[Connection.UNDEFINED] = 'Sem definição';
//alert(status[suaNet]);
var result = "<p style='text-align:center'><img style='height:20em;width:20em;' src='img/icon-dove-1024x934.png'></p>";
var blank = "<ul class='nav navbar-nav'><li style='texto-menu'><a href='#'>Nothing here</a></li></ul>";
if(Connection.NONE || Connection.UNKNOWN === false)
{
BootstrapDialog.alert("hi");
}
else if(Connection.NONE || Connection.UNKNOWN === true){
document.getElementById('div-inteira').innerHTML = result;
document.getElementById('menu-barra-hamburguer').innerHTML = blank;
}
else{
console.log("doest works");
}
are you doing this after device.ready function ?
Try consoling the network type before you check for the connection's. And make sure your using the correct implementation of the plugin.

My JavaScript works as inline code but not as an include file. Any ideas why and how to fix it?

I have this form:
<form id="searchForm" class="search_field" method="get" action="">
...
...
</form>
Then this javascript:
var form = document.getElementById("searchForm");
form.doSearch1.onclick = searchPage;
form.doSearch2.onclick = searchPage;
form.showFeatureChoices.onclick = function( )
{
var cbs = form.featType;
for ( var c = 0; c < cbs.length; ++c )
{
cbs[c].checked = false;
}
document.getElementById("featuresDiv").style.display = "block";
}
function searchPage()
{
var form = document.getElementById("searchForm");
var searchText = form.searchBox.value.replace(/-/g,"");
form.searchBox.value = searchText;
if (searchText != "")
{
// collect features to search for:
var features = [ ];
var featTypes = form.featType;
for ( var f = 0; f < featTypes.length; ++f )
{
if ( featTypes[f].checked ) features.push( featTypes[f].value );
}
featureList = "'" + features.join("','") + "'";
searchMsg("Searching for '" + searchText + "' ...");
// startStatusUpdate(1000);
// findTask.execute(findParams, showResults);
var accord = dijit.byId("accordianContainer");
var resultsPane = dijit.byId("resultsPane");
accord.selectChild(resultsPane,true);
doSearch( searchText, featureList );
}
else
{
searchMsg("No search criteria entered, enter search text");
}
}
If I embed this code in same file as the <form..., it works fine.
If however, I have this js in another file and use as include file:
<script type="text/javascript" src="Views/JS/main.js"></script>
I get following error: "Object required" and it points to these lines:
form.doSearch1.onclick = searchPage;
form.doSearch2.onclick = searchPage;
Any ideas how to fix this?
Just a bit more info, the js code shown above in a file called main.js which is in a folder called JS and Js is in a folder called Views. The
Thanks a lot in advance
When you include the JavaScript code in the same page, where is it in relation to the form element? (Before or after it?) How about when you reference the external JavaScript file?
I'm guessing that in the former case the code is at the end of the file, while in the latter case the script reference tag is at the beginning?
If that's true then what's happening is this code is being executed before the DOM is ready:
var form = document.getElementById("searchForm");
form.doSearch1.onclick = searchPage;
form.doSearch2.onclick = searchPage;
If the form tag hasn't been rendered to the DOM yet then that first line won't find anything, and the subsequent lines will fail as a result. One approach is to put the script reference tags at the end, but that seems like a hack to me. Sometimes there are good reasons to keep them in the page header, not the least of which is cleaner management of the code in many cases. There are other ways to hold off on executing JavaScript code until the DOM is ready.

send from javascript to actionscript IE problem

I tried to send a string from an html page (with javascript) to a swf file (action script 2).
i searched in google, found this page.
but the example code (version 1, not 2, you can find it in the source file .zip) didn't work in IE (IE said: object doesn't support this property or method)
where is the problem? (i don't want to use SWFObject.)
the action script :::
//From Evan Mullins # circlecube.com
//View post at http://blog.circlecube.com/2008/02/01/actionscript-javascript-communication/
import flash.external.*;
//Set up Javascript to Actioscript
var methodName:String = "sendTextFromHtml";
var instance:Object = null;
var method:Function = recieveTextFromHtml;
var wasSuccessful:Boolean = ExternalInterface.addCallback(methodName, instance, method);
//Actionscript to Javascript
//ExternalInterface.call("recieveTextFromFlash", _root.theText.text);
function recieveTextFromHtml(t) {
_root.theText.text = t;
}
_root.button.onRelease = function() {
ExternalInterface.call("recieveTextFromFlash", _root.theText.text);
_root.theText.text = "";
}
js:::
function recieveTextFromFlash(Txt) {
document.getElementById('htmlText').value = Txt;
}
and the onclick js code:::
getElementById('flash').sendTextFromHtml(htmlText.value); document.getElementById('htmlText').value = ''
Thank you.
give this javascript code a try?
function getFlashMovie(movieName) {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
}
function addToResults(results) { getFlashMovie("flashdemo").addToResults(results); }

Categories