I am attempting to get the window of an iFrame using the following code:
var frameWindow = document.getElementById("loginframe");
var iWindow = frameWindow.contentWindow;
Unfortunately, I keep getting the following error:
Property 'contentWindow' does not exist on type 'HTMLElement'.)
As you can see in the screenshot below, "contentWindow" is highlighted in red which is an error...
I have tried casting:
let map = document.getElementById("loginframe") as HTMLObjectElement;
let insideDoc = map.contentDocument;
But this does not work either...
Is this something to do with angular libraries that perhaps I need to include?
First of all you shouldn't select a DOM element like that you should use a viewChild to do that.
<iframe src="urlHere" #loginframe ></iframe>
Then you can use it in your TypeScript code like this:
#ViewChild('loginframe') loginframe: ElementRef;
After that you can select the element like this: (Note: you should cast it to a HTMLIFrameElement)
const win = (<HTMLIFrameElement> this.loginframe).nativeElement.contentWindow;
Here is a fully working plnkr! (open your console to see the output)
https://embed.plnkr.co/kicS6o8QlOEcXyMKNjFi/
Related
I am working on a next js project , copied some coe on code pen , it is used for a product design of an e commerce website . However i am having this problem.
TypeError: Cannot set properties of undefined (setting 'className'). What is an equalvalent of
getElementsByClassName or how can i override this eror
here is a glimse of the code
var slider = document.getElementsByClassName("sliderBlock_items");
var slides = document.getElementsByClassName("sliderBlock_items__itemPhoto");
var next = document.getElementsByClassName("sliderBlock_controls__arrowForward")[0];
var previous = document.getElementsByClassName("sliderBlock_controls__arrowBackward")[0];
var items = document.getElementsByClassName("sliderBlock_positionControls")[0];
You can use:
document.querySelector(".your_class_name").value
querySelector() can be used to select elements on a page, just pass in a CSS like selector...
Cannot set value of undefined would mean that you are trying to select HTML elements that are not on the page. This could mean your code gets run before the components get rendered
Share your full code, or add that code inside a useEffect()
I am new to this ckeditor.
So, I was trying out something very simple. I want to inline edit this p element.
<p class="h_text" >is your site working?</p>
So, I have this script
$(document).ready(function () {
CKEDITOR.disableAutoInline = true;
var elementToEdit = $("body").find("p.h_text").first();
console.log($(elementToEdit).length);
console.log($(elementToEdit).html());
$(elementToEdit).attr('contenteditable', 'true');
CKEDITOR.inline(elementToEdit);
});
When I load the page I get this error thrown from ckeditor.js
TypeError: this.$.nodeName is undefined
From the 2 console.log output, I can confirm that the elementToEdit is valid and not null.
I got this working by changing this line in script
CKEDITOR.inline(elementToEdit);
to this
$(elementToEdit).ckeditor();
To be honest, I did not quite understand why this works and the first one does not.
It would be helpful if anyone explains this.
Try this,
var elementToEdit = $("body").find("p.h_text")[0];
instead of this,
var elementToEdit = $("body").find("p.h_text").first();
Hi have an Windows Store App that need to reference a single Winmd file.
I've added it adding as a normal DLL, that's the correct way?
As my understanding I'm trying to "instantiate" it on my default.js as below:
var helloTest = new WinJS.HelloWR.HelloRT();
With that I'm able to access its methods as:
var ret = helloTest.helloRt();
The problem happens when I try to run it, it raises the following exception:
0x800a138f - JavaScript runtime error: Unable to get property 'HelloRT' of undefined or null reference
It means that my HelloWR namespace is undefined, I've been looking around google for some similar sample but I've found anything.
Let me know if anyone need more info about the content of this winmd.
For those whom faces the same problem, I just did as below:
var helloTest = new HelloWR.HelloRT;
It's not needed to put WinJS as the question at the Top.
Now I'm able to access its methods:
var ret = helloTest.helloRt();
//ret returns 'HelloRT'
If someone explain it better I will check as answer.
I'm fixing a simple user input mulptiplication table which has been littered with errors.
I'm stuck with a partucular piece of code and do not understand what it means.
When the script is run in firbug it says "TypeError: document.getElementById(...) is null"
This is the code which is attached to html:
var get = function(name){return document.getElementById("name").value;};
var set = function(name,value){document.getElementById("name").value=value;};
That simply means that there is no element with an id property of "name" in the DOM. Perhaps your code runs before the document is ready?
It looks like this code is meant to query the DOM for an element with the id of name:
var get = function(name){return document.getElementById(name).value;};
var set = function(name,value){document.getElementById(name).value=value;};
It means that the element with id = "name" is not found in document. Look in the dom if it exists.
You can also try to add this code as event handler for ready-event to check that it works ok there - as it is already said maybe you run this code before the dom is loaded.
Script threw an uncaught JavaScript error:
Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().mainWindow().popover().actionSheet().buttons()["Save Note"]
Code:
var target = UIATarget.localTarget();
var app = target.frontMostApp();
var window = app.mainWindow();
target.logElementTree();
UIALogger.logPass("Stick Note Save Start");
app.navigationBar().toolbar().buttons()["Plus"].tap();
app.keyboard().typeString("Ki");
window.popover().actionSheet().buttons()["Save Note"].tap();
UIALogger.logPass("StickNoteSaveEnd");
First of all, check correct hierarchy.
Then, try to use
"app.popover().actionSheet().buttons()["Save Note"].tap();"
If it does not work for you, please give some details regarding elements structure/buttons.
I think there is a bug in action sheet access from javascript. You can see my answer to a similar question here.
Bascially I think actionSheet() always returns nil to buttons and elements. It's not supposed to, but everything I've seen suggests otherwise.
MikhailV worked out a function to tap the correct button here.