打开带有动态内容的窗口 [英] open window with dynamic content

查看:76
本文介绍了打开带有动态内容的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从PHP中打开一个具有预定义内容的窗口?很明显,您可以如何从构建现有页面的JavaScript链接打开窗口,或者只需从引用现有页面的常规标签中执行target = _blank。但我正在生成一些内容,并希望在新链接中打开该内容(或流式传输给观看者) -



类似于(明确伪码!):

  $ content =Hello World。< br />>很高兴认识你! 

< a href =#target =_ blankcontent = $ content>打开!< / a>

这可能吗?
Thanks!

解决方案

那么,直接回答你的问题是,你不能从PHP直接,因为它是打开窗口的浏览器。但是,您可以让页面打开一个窗口,获取文档对象并写入:

  var w =窗口.open(惊喜,#); 
var d = w.document.open();
d.write(<!DOCTYPE html>< html>< body> Hello World< / body>< / html>);
d.close();

当然,您的PHP脚本可以放在一起,而不是简单的字符串Hello World。此外,如果需要,Javascript代码本身可以根据页面状态,表单域等动态生成内容。

注意,您不能保证新窗口将不会是一个新标签,与< a> < form> 标签。



编辑—另外,如果你尝试在运行时响应click的代码之外使用 window.open ,浏览器可能会认为你试图显示一个弹出窗口,并且会阻止它。


Is it possible to open a window from PHP that has predefined content? It's obvious how you can open a window from a javascript link that frames an existing page, or just do a target=_blank from a regular a tag that references an existing page. But I am generating a bit of content, and want that content to be opened in a new link (or streamed to the viewer)--

something like (clearly psuedo code!):

$content = "Hello World. <br />Nice to meet you!";

<a href="#" target="_blank" content=$content>Open up!</a>

Is this possible? Thanks!

解决方案

Well, the direct answer to your question is that you can't really do it from PHP directly, because it's the browser that's going to open the window. You can, however, have your page open a window, get the document object, and write to it:

var w = window.open("Surprise", "#");
var d = w.document.open();
d.write("<!DOCTYPE html><html><body>Hello World</body></html>");
d.close();

Instead of the simple string "Hello World" of course your PHP script can put together whatever it wants. Additionally, if desired, the Javascript code itself can dynamically generate the content based on page status, form fields, etc.

Note that you can't guarantee that the new window won't be a new tab, which is no different than what happens with "target" in <a> or <form> tags.

edit — oh also: if you try to use window.open outside of code that's running in response to a "click", browsers will probably think you're trying to show a pop-up ad and will block it.

这篇关于打开带有动态内容的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆