问题标签 [html-object]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
javascript - 获取变量的值
In my global html template, I have embedded an iframe
, which can live-preview {{src}}
(eg, src
could be public/tmp/bDCZ5rynnpLaYNEuAAAj/index.html
).
The index.html
is a file written by my server; I have control of the code and I can modify it. index.html
contains JavaScript code, it is designed such that it always has an internal variable $output
.
My question is, how to get the value of $output
out of the iframe
and let the global html page know the value.
Does anyone know how to accomplish this?
Edit 1: I am also open to solutions where index.html
could send the value to the server or create a file with the value, as long as the global template could get it later. Additionally, as I mention in comments, the purpose of iframe
is to live-preview a folder of files, there are other ways to do so (eg, using <object>
), does anyone know which way could let me get an internal value out?
Edit 2: I have made a plunker with iframe and a plunker with object. $output
is defined by <script>var $output="Default"</script>
in indexOutput.html. My goal is to get this value out.
Edit 3: I just realised that window.parent._resetter
that @Roy suggested in his answer works. But one thing is, the _resetter
function must be defined in the script of the html page. Does anyone know how to pass this value to my controller? Here is a plunker, and a plunker with $window.
javascript - Reference object window's element ids with JS
I'm using a template.html file to house my header & menu bar and using JS to insert page content per individual index.html files. I house template.html in my root file and subfolders house an index.html (which pulls in the template.html as an object) and script.js.
I need the index.html file to load the script.js file while still having the script.js file apply to the template.html file, but cannot figure out how to have the JS reference inside the index.html object. I've seen something done like this before-ish for iframes, but could not get it to apply the same way for object elements.
Here's the shortened files:
template.html
references/index.html
references/script.js
As is, the script.js only works if it's loaded within the template.html, but it needs to be loaded within the index.html. Is there a way to load it in index.html but still let it reference elements within the template.html object? Thanks for your help!
jquery - html 对象元素显示加载进度
data
一旦我设置了我的 html 对象元素的属性,我想显示加载进度。
这就是我目前的做法:
HTML
加载网址
我尝试使用onloadstart
andonloadeddata
事件来显示一些基本进度,但它们似乎没有触发;
以上两个事件在 w3school 中有描述,所以不确定我做错了什么,但没有控制台错误。
javascript - 获取带有缓存的 HTML 后备图像?
我有一个用户图像控件,一个标识 - 如果用户有一个图像集,它应该显示它,如果没有,它会显示带有彩色背景(和其他一些 HTML)的他们的首字母。
这些图像有很多,一次显示很多,而且同一个用户可能会在一个页面上加载多次。图像可以包含 alpha 透明度,并以多种不同的背景颜色显示。图像可以是高 DPI,而后备(以及它们旁边显示的大多数其他图像)使用 SVG。
图像可以更改,但不会经常更改。通常它们可以被缓存几天或几周。
我认为有两种方法可以解决这个问题:
JavaScript
在此模型中,服务器返回我缓存IndexedDB
的 JSON,并且 JSON 包含图像的数据 URI(如果已设置)。需要额外的 JS 来检查是否已经为同一用户发出请求并避免重复。HTML
<object>
回退
为此,服务器返回实际的图像字节,如果未找到则返回 404。然后,如果找不到图像,则<object>
标记的内容呈现:
JS 选项有很大的缺点,因为即使 JS 被高度优化也IndexedDB
意味着回调(或同步选项,如LocalStorage
,往往很慢)。这涉及相当多的 JS,这应该是一个相当简单的任务。它有一个很大的优势——它只要求每个用户的照片一次。
我喜欢<object>
回退的简单性,它有一些小缺点(许多奇怪的规则适用于对象内的 HTML 的呈现方式),但有一个主要问题:如果找不到图像,它每次都会再次往返服务器. 很多用户没有图像。每个页面加载都会获得一长串 404 的用户图像,它应该已经知道没有。
- JS 是最好的方法,坚持下去 - 有什么方法可以减少 JS/开销?
- 离开
<object>
404s。 - 添加一个事件,
<object>
当它无法加载图像时触发一些 JS,但我不确定如何在不恢复到 (1) 的情况下阻止它再次尝试 - 更改服务器响应以返回用户图像,即使它失败。
这失去了后备的优雅,并意味着大量的服务器生成的图像。
这就是 SO/gravatar 所做的,但对我们的高 DPI 屏幕来说意味着一些问题。 - 更改服务器响应以在失败时返回透明图像。
这意味着同一张图片会被缓存很多次,即使对于有照片的用户来说,也意味着对内容进行分层。它还会导致带有 alpha 透明度的图像出现问题。 - 调整服务工作者以处理对用户图像的请求作为特殊情况,缓存 404 响应并在再次尝试时跳过网络往返。
- 滥用其他一些 HTTP 状态响应,这些响应
<object>
仍然被视为无法找到图像并回退到内容,但由浏览器缓存。 - 还有什么办法?
所有这些都涉及妥协,但我也相当确定我在这里重新发明了轮子 - 很可能有人(在所有已经存在的标识实现中)已经解决了这个问题。谁能指出我正确的方向或建议解决问题的最佳方法?
jquery - 如何让对象附加 svg?
谷歌浏览器 v60.0.3112.101、HTML5、jQuery 3.2.1
我的object
元素与svg
-file 链接。这svg
在我的 html 页面上显示没有问题。我尝试svg
使用 jQuery 获取元素,但两次尝试都没有找到:
这是我的 html 块:
我怎样才能得到我svg
的 jQuery?
PS 我使用这种方法(一个外部svg
文件),因为我svg
将在许多网页上使用。我也使用object
而不是img
因为它svg
使用外部css
文件。
html - 如何使用对象标签嵌入 YouTube 视频?
我正在尝试object
在 HTML 中按标签包含 YouTube 视频:
目前,视频不显示。我在 W3Schools 上进行了搜索,他们有类似的代码,但 URL 不同,并且可以正常工作:
我可以为object
data
属性使用哪种 URL?
html - 将 pdf 对象的大小调整为父 div 大小
我在网页上呈现 .pdf 和 .png 文件。
base64 编码字符串在哪里report._source.attachment
,例如 pdf 字符串开头JVBERi0x...
和 png 字符串 - iVBORw0KGgo...
。
我的风格(更少)规则:
图片 (png) 已正确调整大小。但是上面的样式对pdf没有任何影响。
如何调整 pdf 的大小以适应父 div 的大小?
这是plunker 中的模拟。我需要的是相同大小的 pdf 和 png 没有硬编码width
和height
.
html - 嵌入 pdf 时,页面不再滚动
所以假设我像这样将我的 pdf 嵌入到我的页面中,这样整个页面就是 pdf 文档。例子
我得到的问题是,当您在对象(pdf)内部滚动时,它只会滚动对象,所以当它全屏时没有任何反应。我希望用户能够滚动网站,而不是 pdf。
还有一种方法可以更改对象 pdf 背景颜色吗?
感谢您的帮助,似乎没有太多关于此的文档。如果您对集成整页 pdf 有任何其他建议,请告诉我。我正在使用纯 HTML/CSS。
php - 禁用正在预览网站的 html 对象的交互性
我正在使用以下代码加载网站的预览:
有没有办法禁用与该链接中元素的交互性?我想加载链接的预览,但如果有意义的话,我不希望用户四处点击并与预览进行交互。