使用Inject从Webbrowser控件禁用/覆盖某些Javascript?

时间:2022-11-11 23:12:11

I am trying to access a page that has certain javascript that causes errors and prevents the page from fully rendering.

我试图访问具有某些导致错误的javascript并阻止页面完全呈现的页面。

<script language="Javascript">
parent.hidden.vPageState = parent.hidden.NEW_LIST;
</script>

and

<body  onload="top.menu.activateCell(3);">

Both of these errors are related to the fact that I am accessing the page directly and not via frames.

这两个错误都与我直接访问页面而不是通过框架这一事实有关。

I've gotten around this by making my own clone of the page and hosting it but I don't like that solution and was wondering if there was a way to somehow

我通过制作我自己的页面克隆并托管它来解决这个问题,但我不喜欢那个解决方案,并且想知道是否有办法以某种方式

Override/Alter or better yet Erase that code using Javascript injection via Webbrowser control

覆盖/更改或更好地通过Webbrowser控件使用Javascript注入擦除该代码

Thanks

1 个解决方案

#1


For the onload event, just replace it with a new function further down the page.

对于onload事件,只需将其替换为页面下方的新功能即可。

http://haacked.com/archive/2006/02/05/AddingWindowOnloadEventsInJavascript.aspx

The other one might be a little trickier....If you can't remove it, you could technically create a frame around the page which doesn't show, so the code would fire properly.

另一个可能有点棘手....如果你不能删除它,你可以在技术上创建一个框架周围没有显示,所以代码将正常启动。

#1


For the onload event, just replace it with a new function further down the page.

对于onload事件,只需将其替换为页面下方的新功能即可。

http://haacked.com/archive/2006/02/05/AddingWindowOnloadEventsInJavascript.aspx

The other one might be a little trickier....If you can't remove it, you could technically create a frame around the page which doesn't show, so the code would fire properly.

另一个可能有点棘手....如果你不能删除它,你可以在技术上创建一个框架周围没有显示,所以代码将正常启动。