Remove DOM element with Javascript

0
0

Hi guys,

I’m using WiseJ 2.2.60 with VB.Net to develop a web application.

In a form, I put an IframePanel to host an external site.

Now I need to hide the top bar of this site with something like this:

document.querySelector(‘.header’).hidden = true;

but I don’t know how to add this javascript and to what event (I need that the content of the iframe is loaded)

Any suggestions ?

 

TY ALL,

Emiliano

  • You must to post comments
0
0

Hi Emiliano,

Attached is a sample app.

The event you’ll need is the DocumentCompleted even.

You can use this.iFramePanel1.Eval(“some_js_code”) to evaluate javascript in the iFrame.

on the Client side, this.iFramePanel1.Eval(“this.getWindow()”) to get the framed window, and this.iFramePanel1.Eval(“this.getDocument()”) to get the framed document.

can also do this this.iFrame1.Call(“My_js_function”) and in My_js_function use this.getWindow() or this.getDocument(). If CORS allows it it returns the window or the document objects.

HTH,
Alaa

//

  • Emiliano Savi
    I’ll take a look ASAP, thank you in advance
  • Emiliano Savi
    Mhh … it doesn’t work … this.getDocument() return null. I tried with your example setting iFramePanel1.Url = “https://www.gazzetta.it/”;
  • Luca (ITG)
    That means it’s not allowed by the browser. Look at the console, there should be an error. You can also try by typing javascript in there referring the iframe. The content of the iframe must be from the same source, it’s not a Wisej restriction.
  • Emiliano Savi
    The event is fired twice: the first time the alert(this.getDocument()); says [object HTMLDocument], the second time null. Using MS EDGE I have no error in the console (i’m debugging with Visual Studio in localhost), only a warning in the Issues tab saying: Frames must have an accessible name: Element has no title attribute
  • You must to post comments
0
0

Hi Emiliano,

First of all, you’ll have to make sure that the website you’re framing is from the same origin, otherwise, the browser would block all cross-frame javascript.

There’s a similar topic here on the Forum, you can read all about it here.

Best,
Alaa

//

  • Emiliano Savi
    Keep it simple. No problem with CORS and other security stuff. I need the code, I suppose javascript, to add to my WebForm to remove a div from the document contained in my IFramePanel. Thank you.
  • You must to post comments
0
0

Hi Emiliano,

Can you elaborate on what’s the “top bar” you’re referring to?

It’s not really advised to use querySelector with Wisej.NET applications unless you have a specific way of identifying your widget. (i.e. something like a CSS Class name you made)

What you’re looking for is a child control, but without knowing which control you’re trying to modify it’s hard to guess!

Thanks,
Alaa

  • Emiliano Savi
    The “top bar” is part of the web site hosted inside the IFramePanel, it’s just a DIV that I need to remove/hide programmatically. No widget or something strange, I just assign an URL to the IFramePanel and I need to remove a DIV identifyed by the class name “header”.
  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.